ProgrammingModerateTCS NQT · C

What is printed?

What is printed?
int a[5] = {1, 2};
printf("%d %d %zu", a[1], a[2], sizeof a / sizeof a[0]);
  1. A. 2 0 2
  2. B. 2 garbage value 5
  3. C. 1 0 5
  4. D. 2 0 5

Correct answer: D. 2 0 5

A partial initialiser zero-fills the remaining elements, so a[2] is 0; sizeof a / sizeof a[0] is the element count, 5.

More C Programming questions

Exams that ask this topic