I wrote this code and ran it:
#include <stdio.h>
int i;
int a[] = { 1 };
int main()
{
for (i = 0; i < 10; i++)
printf("%d\n", a[i]);
};
It always gave me the following result
1
0
2
0
0
0
0
0
0
0
I know the length of a[]
is 1 and a[1],a[2]...
are invalid. But I re-compiled it again and finally I found a[2]
always give 2
, I am quite confused about the 2
, where did it come from and why a[2]
is not other numbers such as 0
or some random number?