#include <stdio.h>
int main()
{
int a[5]={1} ;
int b[5];
b[0]=1 ;
printf("\na[0]=%d, a[1]=%d, a[2]=%d, a[3]=%d, a[4]=%d",a[0],a[1],a[2],a[3],a[4]);
printf("\nb[0]=%d, b[1]=%d, b[2]=%d, b[3]=%d, b[4]=%d",b[0],b[1],b[2],b[3],b[4]);
return 0 ;
}
Look at the code. I have assigned two integer array partially (1 element is assigned out of 5) in two procedure.
1st one is assigned at once with braces.
2nd one is assigned by accessing one array index.
And then I am printing the whole array.
In 1st array I am getting 0 (zero) in unassigned index. And in 2nd array I am getting garbage value in unassigned index.
May you please explain.
Please don't explain what is happening here. But kindly explain why it is happening? The reason.