calling by reference

// PassObjRef - change the contents of an object in
// a function by using a reference
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
class Student
{
public:
int semesterHours;
float gpa;
};
// same as before, but this time using references
void someFn(Student& refS)
{
refS.semesterHours = 10;
refS.gpa = 3.0;
cout << “The value of refS.gpa = “
<< refS.gpa << “\n”;
}
int main(int nNumberofArgs, char* pszArgs[])
{
Student s;
s.gpa = 0.0;
// display the value of s.gpa before calling someFn()
cout << “The value of s.gpa = “ << s.gpa << “\n”;
// pass the address of the existing object
cout << “Calling someFn(Student*)\n”;
someFn(s);
cout << “Returned from someFn(Student&)\n”;
// the value of s.gpa is now 3.0
cout << “The value of s.gpa = “ << s.gpa << “\n”;
// wait until user is ready before terminating program
// to allow the user to see the program results
system(“PAUSE”);
return 0;
}

IN this program not able to understand "someFn(Student& refS)" my mind is overflowing with all wh questions .Not able to understand "&" operator after Student.
I'm not sure I understand what you're asking. Are you getting an error when you compile?
anudes wrote:
Not able to understand "&" operator after Student.
It is not an operator in this context, it is a type modifier. It changes the type from "Student" to "Reference to Student".
Topic archived. No new replies allowed.