C Programming · Question 11 · Medium

What will be the output of the following C program?

#include <stdio.h>

int main(void) {
    int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
    int *p = &m[0][0];
    printf("%d %d", *(p + 4), *(*(m + 2) + 1));
    return 0;
}
  1. 5 8
  2. 5 6
  3. 4 8
  4. 2 7
Answer and explanation

Answer: A. 5 8

Explanation: A 2D array is stored row by row, so p + 4 points to the 5th element, 5. *(m + 2) is row 2 ({7, 8, 9}) and adding 1 selects 8.

Previous: What will be the output of the following C program? · Next: What will be the output of the following C program?

Practise c programming

Try a fresh set of c programming questions with an explanation after every answer, free and without signing up: C Programming practice. Or sit a full placement mock test.

More c programming questions

More technical & programming practice

Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge