myfunc (int a)
return a + 2;
main (int argc, char *argv)
printf ("myfunc(2)= %d\n", myfunc (2));
As you can guess, this function will return "4".
Parameter "a" was definitely "passed by value" ...
... and function "myfunc()" definitely returns an "int" ...
... but I wouldn't see the value 4 was "returned by value". I'd merely say "function 'myfunc ()' returned an int".
This applies equally to C and C++.
The big differences here are:
1) C++ absolutely *requires* you to specify the return value type (or specify "void" if there is *no* return value), classic "C" would default to "return int". You should *always* explicitly declare your return value, in *both* C and C++. Whether you get a compile error or not
2) C++ would allow either/both the parameter and/or return value to be a reference ("&"). C doesn't support references (at least not the last time I looked). Pointers: yes. References: no.
'Hope that helps .. PSM
No, there's no "extra memory space". An integer return value is usually copied to a register (for example, "eax" for an Intel CPU).