Here is how the C 2018 standard says function calls are executed, in 6.5.2.2 4:
In preparing for the call to a function, the arguments are evaluated, and each parameter is assigned the value of the corresponding argument…
What this means is that, in the function definition with void doSomething(int b)
, b
is defined to be a variable (technically an object) on its own, and, when the function is called with doSomething(a)
or doSomething(5)
, the value of a
or 5
is assigned to b
, as if you did b = a
or b = 5
. It is just an assignment; it does not create any enduring connection between b
and a
or 5
.
Inside the function, b
is a variable, so of course you can execute the assignment b = 6
. This simply assigns 6
to the variable b
.
Here is more about how parameters are their own variables. 3.16 defines parameter as:
… object declared as part of a function declaration or definition that acquires a value on entry to the function,…
6.9.1 9 says:
Each parameter has automatic storage duration; its identifier is an lvalue…
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…