Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (anonymous):

hi .can anyone tell me how to call a function by the reference ? c++

OpenStudy (anonymous):

void functionName(int & x) { //function body }

OpenStudy (anonymous):

when u call a variable by function this means that the changes u make to it .. change the value of the actual variable and these changes can be seen in any other part of the program ...this gives u the ability to "return" more than one variable in a function ... int myfunc(int n, int &x) { x++; return n++; } main(){ int n=0; int x=0; cout << myfunc(n,x); // value of both x and n is incremented by 1 and this prints the // value of n which is 1 cout << x ; //will print 1 return 0; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!