pass by value and pass by reference

// explain difference between pass by value and pass by reference
void addOne(int i)
{
i++;
}
void addOne(int& i)
{
i++;
}
When a variable is passed by value it copied into the stack. This means that the instance being used in the scope of the function it was passed to is an individual instance of the original object created from that objects copy constructor. This means that any changes made to it are not reflected back onto the source object.

When a variable is passed by reference then it's that original instance of the variable that is operated on in the scope of the function\lambda (<- is that a redundant distinction?). This also means that no copy or assignment operators are used to move it to the function.

This kind of question would get more responses in the "beginners" section by the way. You can edit and move your topic if you'd like.
Topic archived. No new replies allowed.