in Programming in C recategorized by
485 views
5 votes
5 votes

Consider the following C code:

double A[2][3] = {{1, 2, 3}, {4, 5, 6}};

Assume that A[0] = 0xFFAA0000  and the sizeof(double) is 8.

What will be the value of `A[1]`?

  1. 0xFFAA0024
  2. 0xFFAA0003
  3. 0xFFAA000C
  4. 0xFFAA0018

in Programming in C recategorized by
485 views

1 Answer

4 votes
4 votes
In C, when you have a 2D array like `double A[2][3]`, the memory is laid out in a contiguous fashion in row major order. Assuming `sizeof(double)` is 8, let's analyze the memory layout.

Given that `A[0] = 0xFFAA0000`, this means that the starting address of `A` is `0xFFAA0000`. The size of each element in `A` is `sizeof(double)`, which is 8 in this case.

Therefore:
 A[1] would start at the address `0xFFAA0000 + 3 * sizeof(double) = 0xFFAA0000 + 3 * 8 = 0xFFAA0018 (24 in decimal is same as 18 in hex )

So, the correct answer is: 0xFFAA0018
Answer:

Related questions