In C, is { a[i] = a[++i] } equivalent to { a[i] = a[i+1]; i++;}?

1k views Asked by At

In C, is

a[i] = a[++i];

equivalent to

a[i] = a[i+1]; i++;

That is, which side of the assignment is evaluated first and what value of i is used on the left side? Or is this assignment ambiguous?

1

There are 1 answers

0
Gopi On BEST ANSWER

In the same sequence point you are using and incrementing i

a[i] = a[i++];

which will lead to undefined behavior.

a[i] = a[i+1];
i++;

is good.

And to answer your question are they same ? No they are not !! One if well defined and another is not.

Check this answer