ProgrammingHardTCS NQT · Infosys

What is printed?

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

Correct answer: D. 4

a + 1 and 1 + a are the same address, so both reads give 2, and their sum is 4.

More C Programming questions

Exams that ask this topic