ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
int a[2][3] = {{1,2,3},{4,5,6}};
int *p = &a[0][0];
printf("%d ", *(p + 4));
int (*rows)[3] = a;
printf("%d", (*(rows + 1))[1]);
  1. A. 5 5
  2. B. 4 5
  3. C. 4 4
  4. D. 5 4

Correct answer: A. 5 5

p walks the array flattened, so p+4 is the 5th element overall: a[1][1] = 5. rows points at whole rows; *(rows+1) is row 1, and [1] of that is a[1][1] = 5. Both expressions reach the same element.

More C Programming questions

Exams that ask this topic