edited by
457 views
7 votes
7 votes

On a $64$-bit system, which of the following C expressions is equivalent to the C expression $(x[2]+4)[3]?$  Assume $\mathrm{x}$ is declared as $\textsf{int}\ast \ast \textsf{x}$

  1. $\ast((*(x+16))+28)$
  2. $\ast((*(x+2))+7)$
  3. $\ast(((* x)+2)+7)$
  4. $(* \ast(x+2)+7)$
edited by

2 Answers

4 votes
4 votes
Let's break down the expression (x[2] + 4)[3]

   x[2] is equivalent to *(x + 2) because the array subscript operator is equivalent to pointer arithmetic

   + 4 adds 4 to the result of *(x + 2)

    [3] is equivalent to adding 3 to the expression obtained so far

So the final expression will be *((*(x + 2)) + 7)
1 votes
1 votes

a[2] is equivalent to *(a + 2), here in (x[2] + 4)[3])  x[2] is equivalent to *(x+2).

So, (*(x + 2) + 4)[3]. 

And assume *(x+2)+4 as a then a[3] is *(a + 3).

Therefore, *(a + 3) is *(*(x + 2) + 4 + 3) = *(*(x + 2) + 7).

Answer: