int increment(const int& myvalue);
I'm considering here the apparent uselessness (If I don't want my argument to be changed, why did I declared a reference to it in the first place?)
Since not everything is what it seems at first glance (certainly not in C/C++), I started to think of the possible reasons of why would I want to do such a thing.
I came up with the following:
Pass-by-reference avoids the waste of creating space in memory to accomodate a copy of the variable passed to a function (which is what happens on a pass-by-value). So, maybe the above can be useful if the argument to be referenced is a big one (memory-wise). This way I save memory while the function is running, since no copy of the variable was created. Just a reference to its memory location. Big arrays of strings , objects and multi-dimensional arrays are candidates here.
My question is, is this right? Or am I overlooking yet some other advantage?