Friday 5 April 2013

What is passing by reference?

What is passing by reference?

Method of passing arguments to a function which takes parameter of type reference.
for example:
void swap( int & x, int & y )
{
 int temp = x;
 x = y;
 y = temp;
}
int a=2, b=3;
swap( a, b );
Basically, inside the function there won't be any copy of the arguments "x" and "y" instead they refer to original variables a and b. so no extra memory needed to pass arguments and it is more efficient.




Blog Author: Vijay Kumar

No comments:

Post a Comment