ProgrammingHardGATE CS · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int a[3] = {1, 2, 3}, b[3] = {4, 5, 6};
    int *ptr[2] = {a, b};
    int (*pa)[3] = &b;
    printf("%d %d", ptr[1][2], (*pa)[0] + *ptr[0]);
}
  1. A. 6 4
  2. B. 6 5
  3. C. 5 5
  4. D. 6 1

Correct answer: B. 6 5

ptr[1][2] is b[2] = 6. (*pa)[0] is b[0] = 4, and *ptr[0] is a[0] = 1, so the second value is 5.

More C Programming questions

Exams that ask this topic