Logo F2FInterview

C++ Interview Questions

Q   |   QA

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. 

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: