wht is difference between call by and reference function... a bit confusing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

wht is difference between call by and reference function... a bit confusing

trouble

9th Jul 2016, 6:42 PM
Shivaram S Habib
Shivaram S Habib - avatar
2 Answers
+ 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.
9th Jul 2016, 7:40 PM
Albert Gullbee
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()
10th Jul 2016, 4:05 AM
Dheeraj Kumar Chalotra
Dheeraj Kumar Chalotra - avatar