ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    int a[] = {10, 20, 30};
    int *p[] = {a, a + 1};
    printf("%d", *p[1] + *(*p + 2));
}
  1. A. 50
  2. B. 40
  3. C. 30
  4. D. 60

Correct answer: A. 50

*p[1] is a[1] = 20, and *p is a, so *(*p + 2) is a[2] = 30, giving 50. Grouping the star differently gives different elements.

More C Programming questions

Exams that ask this topic