![]() |
![]() |
![]() |
![]() |
![]() |
|
The reason that C acts as though it builds an isolating fence around each
function's parameters is that C reserves a chunk of memory for each
parameter every time that the corresponding function is called. In the
doubling_time example, a new chunk of memory is reserved for the
parameters, r, and the argument's value is
placed in that chunk, as shown here:
Memory reserved for r, Memory reserved for r, a variable in main a parameter in doubling_time *------* *------* | | ---------------------> | | *------* *------*
Thus, the reassignment of the parameter, r, inside the function has
no effect on the value of the variable, r, outside, even though the
names, r and r, happen to be the same.
Because C generally reserves new chunks of memory for parameters and variables, into which values are copied, C is said to be a call-by-value language.