structure reference

Example by: Ira Oldham, References: Savitch eighth edition, section 10.1; Gaddis seventh edition, section 11.7

Structure variables are usually passed to functions by reference.

1  struct Student
2  {
3    int id;
4    char grade;
5  };
6  void getInput(Student & aStudent);
7  int main(void)
8  {
9    Student c;
10   getInput(c);
11   cout << "c.id:    " << c.id    << endl;
12   cout << "c.grade: " << c.grade << endl;
13   return 0;
14 }
15 void getInput(Student & aStudent)
16 {
17   cout << "Enter ID:    ";
18   cin  >> aStudent.id;
19   cout << "Enter Grade: ";
20   cin  >> aStudent.grade;
21   return;
22 }
Enter ID:    1234
Enter Grade: A
c.id:    1234
c.grade: A

The reference parameter can be used to change the values in the member variables in the structure they refer to.