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

Discussion

If x is an array of integers, then the value of &x[i] is same as

  • A.&x[i-1] + sizeof (int)
  • B.x + sizeof (int) * i
  • C.x+i
  • D.none of these

Answer: A

Correct answer: x+i

By definition x[i] is *(x + i), so taking the address of both sides gives &x[i] == x + i. The scaling is already built into pointer arithmetic: adding 1 to an int * advances by sizeof(int) bytes. That is why the two options that multiply or add sizeof(int) explicitly are wrong - they would scale twice.

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

Post your comment

Please log in or register to post a comment.