0
wht is difference between call by and reference function... a bit confusing
trouble
2 ответов
+ 1
You mean call by value and call by reference, I guess.
When you call a function by value
* The argument/s may be direct data or variable/s
* If the arguments aree variables, they do mot change after the function call because only their values are sent.
When you call a function by reference
* You must provide variables as arguments
* The memory addresses of variables are sent to the function, if the function makes changes to those addresses the values of the variables are modified after the call.
0
In Case of Call by value when u pass argument to a function then a bitwise copy of that argument is passed and when function modifies the argument then original argument is not affected.
example :-
int x = 2;
somefunction(x);
Here bitwise copy of x variable is passed to somefunction()
In case of call by reference the memory address to the variable is passed as argument to the function. So when the value is modified at that address by the function the original argument is also affected.
example:-
int x = 2;
somefunction(&x);
Here memory address of x variable is passed to somefunction()