Dark Mode

271 views

3 votes

Consider the following declaration of variable a in C program (row-major order).

int a[3][4][5];

Which of the following(s) is/are TRUE about pointer arithmetic operations?

- Value of $a[2]-a[1]$ is $4$
- Value of $a[1][2]-a[0][3]$ is $15$
- Value of $a[0][10]-a[1][0]$ is $30$
- Value of $a[2]-a[1]$ is $5$

3 votes

**Answer: A,B,C**

__Option A__: a[2], a[1] is pointing to 1D array.

Number of elements between a[1] and a[2] is 4. $\therefore$ a[2] – a[1] = 4

__Option D__: It will be false since option A is true.

__Option B__: a[1][2] – a[0][3] = 15

__Option C__: a[0][10] – a[1][0]

a[0][10] = ((*a+0) + 10) = *a + 0 will point to 1D array adding 10 to it will point to a[2][2] array and de-referencing it will point to a[2][2][0]

$\therefore$ a[0][10] – a[1][0] = 30