Originally Posted by Raigne
is still a return value, because the expression (a+b) results in a value. There are few expressions in C++ which don't result in values of some type; off-hand I can only think of function calls which return nothing. A return value is necessary because otherwise you would not get any of the information that addy(); computes for you.
If you elect not to use return values, you have to use references or the like to change a pre-existing integer.
That looks like this.
If a function returns something, you need to "use it or lose it" or "store it or ignore it". Example, if addy(); returns an int then:
void addy (int &retval)
std::cout << "Enter value for a:";
std::cin >> a;
std::cout << "Enter value for b:";
std::cin >> b;
retval = a + b;
// called like
int retval = 0;
It's not really a complex choice, but if a function returns something you should probably use or check what the value is. It usually means something useful. And in this case, addy() is a sum, so you wouldn't call it if you didn't want a sum.
retval = addy(); // storing it
addy(); // ignoring it
std::cout << addy(); // using it
addy(); // losing it