Functions

Jan 2, 2011 at 10:53am
I am a beginner and i wanted to know what does it mean if the function has a (&) before it name i mean like : int &SetTime (...) ?
Jan 2, 2011 at 11:19am
It is not before the name, but after the return type. It means that it returns a reference.
Jan 2, 2011 at 11:21am
it mean pass by reference.Parameter use the same memory location as argument.Changes are made to argument as well as parameter.Hence the changes are retained after function end.
Jan 2, 2011 at 11:51am
Yts, as you say, what you describe is passing by reference. This is returning a reference, meaning that you return a lvalue. Which means you can actually use it with operators like ++ and -- or on the left side of an assignment operators (=, +=, etc).

So the following would be legit code (although depending on the functionality, it might not really be a logical step to make):
1
2
3
SetTime(...) = 3;
// OR
SetTime(...)++;

Just to name a few.
Jan 2, 2011 at 12:17pm
alright got it ;) thanks guys i really appreciate it .
Topic archived. No new replies allowed.