+ 1

Call by value vs Call by reference.

Can anyone differentiate b/w the two?

12th Dec 2016, 4:58 AM
Khalil Ur Rehman
Khalil Ur Rehman - avatar
3 odpowiedzi
+ 5
call by value passes d copy of a value in a variable which means it wont modify/change the original value of a variable while call by reference passes d orginal value of a variable. which means it will modify/change the original value of a variable. void printValue(int ); void printRef (int*); int val = 5; int ref = 7; int main () { printValue(val); printRef (&ref); cout << val; //prints 5 cout << ref; //prints 10 return 0; } void printRef(int *r) { ref = r + 3; } void printValue(int v) { val = v + 3; }
12th Dec 2016, 5:12 AM
Franky BrainBox
Franky BrainBox - avatar
+ 1
Thanks Raj. I am here to help
12th Dec 2016, 5:44 AM
Franky BrainBox
Franky BrainBox - avatar
0
nice explanation Franky, 👍, it helps, keep up the good work
12th Dec 2016, 5:43 AM
Morpheus
Morpheus - avatar