Link to home
Start Free TrialLog in
Avatar of ubuntuguy
ubuntuguyFlag for United States of America

asked on

C++ Call by reference VS Call by value

I don't really think that I understand the difference between calling by value and calling by reference.

When I call by value, the function doesn't modify variables in the class, but it only creates local variables inside the function?  And when I call by reference, the function actually modifies the variables?

I'm confused.  I've looked online, but I just don't get it.  Can anybody give me as simple Barney style explanation?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ubuntuguy

ASKER

ok I think I I get it... so basically when I call by reference the parameter in the function has to be a variable that already exits, and if its value changes inside the function then its original value is changed too outside the function.  if I call by value then whatever change happens to the parameter inside the function has to effect on its value after the function has been called, the value of the parameter remains the same.

Yes, that pretty much sums it up. Now, if you thing the above sample to pass objects instead of integers, you have the big picture.
thanks