The answer lies in the concept of "pass by value", which means that the called function receives copies of the arguments, which are pointers to int. Thus, a and b are local copies of these pointers (which do not exist in the caller, they were the result of conversions from arrays, that is, the addresses of their first elements). It would not be otherwise if you wrote
void foo( int aparam[2], int bparam[2] ) { int* a = aparam; int* b = bparam; a = b ; }
Dennis Ritchie admitted that the array syntax for the parameters is a wart in the language, and he was only there to facilitate the conversion of B programs - ancient history! It also had a detrimental effect on C ++ design, since arrays cannot be passed by value. This syntax is a constant source of confusion. So ... do not use it ; pretend it's not legal. If everyone does this, he can disappear, and maybe in a few decades he will be given proper semantics.
Refresh . For more information about calling by value (the only form of calling in C and Java, see my comments below), call-by-reference (added in C ++) and other evaluation strategies, see http: // en. wikipedia.org/wiki/Evaluation_strategy
source share