What will be the output of the following C program?
int a[5] = {1,2};
printf("%d", a[3]);
Options
- B. 1
- C. 2
- D. More than one of the above
- E. None of the above
Quiz Practice:
int a[5] = {1,2};
printf("%d", a[3]);
Correct Answer: 0
When an array is partially initialized in C, the elements for which no value is explicitly provided are automatically initialized to 0.
Therefore:
a[0] = 1
a[1] = 2
a[2] = 0
a[3] = 0
a[4] = 0
Hence a[3] is 0.