recategorized by
757 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$
recategorized by

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

Answer:

Related questions

1 votes
1 votes
2 answers
2
GO Classes asked Aug 6, 2022
1,155 views
In which of the following case(s) character array must end with null char?char c[] = "GATE";char c[] = {'2', '0', '2', '3'};char c[4] = "GATE";char c[16] = "2023";