C ++, like C, is the default language, so in the general case, copies of the parameters are always saved.
When:
void f( int x ) { }
its parameter is copied and passed to the function. When:
void f( int * x ) { }
a copy of the pointer is made and passed to the function.
The exception is the use of links:
void f( int & x ) { }
there is no copy, but inside the pointer (probably) is used to pass the parameter address - you should not think about it, however.
Exactly the same thing applies to return values:
int f() { return 1; }
a copy of the value 1 is made and returned to the caller. If the function returns a pointer, a copy of the pointer will be created. References are again an exception, since no copy is made, but internally a pointer (probably) is used to return the value.
anon
source share