Call by reference or by value

0 Kislay Kumar · June 6, 2015
I dont understand the call by reference and by value method...plz help

Post a Reply


Oldest  Newest  Rating
+2 Homer Simpson · June 9, 2015
Pass by value.
Okay so I go to a store and get a cup. I get an identical cup and give it to you. That's in essence what's going on. Whatever you fill your cup with doesn't affect my cup whatsoever. When you pass a number by value, you're duplicating it so there's two copies. 

Pass by reference. 
Okay so I go to a store and get a cup. Instead of getting one for you, I just let you know where I keep my cup and give you access to it(assuming it's not a const cup but that's another story). We therefore use the same cup and whatever you fill it with I must deal with it. 
+1 Anton Wieslander · June 6, 2015
Call by reference  pass(int& a) , the variable you pass to function, it uses the same variable at the same address.
-original value may be modified
-faster because you don't have to create an additional variable

Call by value pass(int a), the variable you pass to the function, will make a copy of the value at another address.
-original value won't be modified

At least that's how I see it, feel free to correct me.
0 c student · June 6, 2015
call by reference takes the original values.  call by value takes copies of the original values.
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator