ProgrammingHardGATE CS · Infosys

What is printed?

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

Correct answer: D. 6

The compound literal (int[]){1, 2, 3} has automatic storage that lasts for the enclosing block, so p[1] * p[2] = 2 * 3 = 6 is defined here.

More C Programming questions

Exams that ask this topic