ProgrammingEasyHCL · Tech Mahindra pattern

What is printed?

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

Correct answer: C. 0

When an array has an initialiser list shorter than its size, the remaining elements are set to 0. So a = {1, 2, 0, 0, 0} and a[3] is 0, even for a local array.

More C Programming questions

Exams that ask this topic