What is the output of the following program?#include<stdio.h> int main() { int a[5] = {2, 3}; printf("%d, %d, %d", a[2], a[3], a[4]); return 0; }Select one:Compilation error2, 3, 30, 0, 03, 2, 2
Question
What is the output of the following program?#include<stdio.h> int main() { int a[5] = {2, 3}; printf("%d, %d, %d", a[2], a[3], a[4]); return 0; }Select one:Compilation error2, 3, 30, 0, 03, 2, 2
Solution
The output of the program will be "0, 0, 0".
Here's why:
In C, when you declare an array and initialize it with fewer elements than the size of the array, the remaining elements are automatically initialized to 0.
In this case, the array 'a' is declared with a size of 5, but only the first two elements are initialized (2 and 3). The remaining elements (a[2], a[3], and a[4]) are automatically initialized to 0.
So, when the printf statement is executed, it prints the values of a[2], a[3], and a[4], which are all 0. Hence, the output is "0, 0, 0".
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.