can someone show me an example of how i will do call a function and its value . i guess maybe the synetex
calling pass by value functions
Collapse
X
-
Passing by value passes a copy of the value of the variable. From that point you can manipulate/modify the value of that copy but you cannot change the original value of that variable.
Passing by reference, the reference variable becomes an alias for the original variable. When you change the value of the alias variable you also change the value of the original variable.
Here is an example where the function`s first argument is passed by value and it`s second argument is passed by reference.
Code:int main() { int a=22,b=44; cout<<a<<b;//prints 22 44 f(a,b);//call the function cout<<a<<b;//prints 22 99 f(2*a-3,b);//call the function again and try to change the //x value cout<<a<<b;//prints 22 99 } voud f(int x, int& y)// the & says y is passed by reference {//changes reference argument to 99 x=88;; y =99; }
Comment