Reference Parameters in C++: VERY basic example please.
- by Sagistic
I am trying to understand how to use reference parameters. There are several examples in my text, however they are too complicated for me to understand why and how to use them. Could anyone give me the MOST basic example of how/why to use one, and perhaps the difference with or without it (what would happen if you didn't attach the '&').
for example, if I've created a function: int doSomething(int& a, int& b), what would be the consequences of not putting in that '&.'
I understand that reference variables are used in order to change a formal-reference, which then allows a two-way exchange of parameters. However, that is the extent of my knowledge, and a more concrete example would be of much help. Thank you.