in Programming in C recategorized by
740 views
5 votes
5 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?

  1. Value of $a[2]-a[1]$ is $4$
  2. Value of $a[1][2]-a[0][3]$ is $15$
  3. Value of $a[0][10]-a[1][0]$ is $30$
  4. Value of $a[2]-a[1]$ is $5$
in Programming in C recategorized by
740 views

1 Answer

3 votes
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

by
Answer:

Related questions