There are several interesting questions raised here regarding undefined behaviour in C. One of them is (slightly modified)
Does the following piece of code r
Let us decompose the expression a[i] = i + 1
will you ?
= -- [] -- a
\ \_ i
\
\_ + -- i
\_ 1
Effectively, a[i]
refers to &i
however note that neither a[i]
nor i+1
modifies i
. i
is only modified when =
(the assignment itself) is executed.
Since the operands of any function need be evaluated before this function takes effect, this is actually equivalent to:
void assign(int& address, int value) { address = value; }
assign(a[i], i + 1);
It is true that =
is somewhat special in that it is built-in and does not result in a function call, still the evaluation of both operands are sequenced before the actual assignment, so they are first evaluated prior to i
being modified, and a[i]
(which points to i
location) is being assigned to.