#include <stdio.h>
int main()
{
int a[100];
int b[100] = {0};
int c[100] = {1, 200};
printf("%d %d %d\n", a[0], a[50], a[99]);
printf("%d %d %d\n", b[0], b[50], b[99]);
printf("%d %d %d\n", c[0], c[1], c[99]);
return 0;
}
Output:
[vnathan.VNATHAN-L430] ➤ ./a.exe
1629978992 1767859565
0 0 0
1 200 0
If none of the array elements were initialized then we have some junk value (a[]) where as if we declare one element (b[]) or first few elements (c[]) then remaining elements in the array were assigned to 0. Why is it so? I expect uninitialized elements to have junk value as array a[].