August 2012
Intermediate to advanced
976 pages
30h 17m
English
When we initialize a nonreference type variable, the value of the initializer is copied. Changes made to the variable have no effect on the initializer:
int n = 0; // ordinary variable of type intint i = n; // i is a copy of the value in ni = 42; // value in i is changed; n is unchanged
Passing an argument by value works exactly the same way; nothing the function does to the parameter can affect the argument. For example, inside fact (§ 6.1, p. 202) the parameter val is decremented:
ret *= val--; // decrements the value of val
Although fact changes the value of val, that ...
Read now
Unlock full access