|
|
Function Arguments |
|
When arguments are passed to a function, a copy is made.
Alterations to the value in the function don't affect the value of the program in the calling routine.
In the following program, the printed value will be 5.
int function ( int x ) {
x = 1;
return ( x );
}
int main () {
int x = 5;
function(x);
printf ("%d\n", x);
return ( 0 );
}
For the simple types that we've covered so far, the effects of copying are minimal. We'll learn that for constructed data types, this copying can be significant and we'll find ways around it.