One of my friend, yesterday sent me this code in C language:
int main()
{
int n = 3 ;
int a[n];
for (int i = 0; i <= 5; ++i)
{
a[i] = i;
printf("%d ", a[i]);
}
return 0;
}
When I saw this first I thought there will be error of index out of bound since inside a for loop we have a[3] = 3 and same for index 4,5 and we are allocating memory for 3 blocks of memory only but then he sent me the output :
0 1 2 3 4 5
And both of us don't have any idea why is this happening , can somebody help ?