Home Segments Index Top Previous Next

124: Mainline

The reason 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 the corresponding function is called. In the box_car_volume example, a new chunk of memory is reserved for the parameters, h, w, and l, and the arguments' values are placed in those chunks, as shown here for l:

Memory reserved for l,          Memory reserved for l, 
a variable in main              a parameter in box_car_volume 
*------*                        *------* 
|      | ---------------------> |      | 
*------*                        *------* 

Thus, the reassignment of the parameter, l, inside the function has no effect on the value of the variable, l, outside, even though the names, l and l, 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.