Machine-translated by Google. Questions are authored in English.
Top

Discussion

If n has the value 3, then the statement a[++n] = n++;

  • A.assigns 4 to a [4]
  • B.what is assigned is compiler-dependent
  • C.assigns 4 to a [5]
  • D.assigns 4 to a [6]

Answer: B

Correct answer: what is assigned is compiler-dependent

The statement a[++n] = n++; both reads and modifies n twice between sequence points, and it uses the value of n on the right while also changing it on the left. The standard leaves the order unspecified, so the compiler may evaluate the subscript before or after the right-hand side. The result is undefined behaviour - what is assigned, and where, depends on the compiler.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.