In the below program I get garbage values for indexes like 2,4 etc
main()
{
int j, arr[10] , a;
int n = 10;
while (n--)
{
scanf("%d", &a);
printf("%d \n", ++arr[a]);
}
}
output
9
0
4
1781349929
3
0
2
395049983
1
0
but when I increase the array initialized index to a large number every index value is assigned zero
main()
{
int j, arr[10000] , a;
int n = 10;
while (n--)
{
scanf("%d", &a);
printf("%d \n", ++arr[a]);
}
}
output
9
0
4
0
3
0
2
0
1
0