How dangerous is it to access an array out of bounds? This does not tell what is the value stored.
When i try to print the out of array size elements as shown in the program, It is printing 0
. Will it be always 0
or some garbage values.
Program
#include<stdio.h>
int main()
{
int a[5] = {10};
printf("\n\ra[6] = %d",a[6]);
printf("\n\ra[7] = %d",a[7]);
printf("\n\ra[8] = %d",a[8]);
printf("\n\ra[9] = %d",a[9]);
return 0;
}
Output
a[6] = 0 a[7] = 0 a[8] = 0 a[9] = 0
My question is what will be value of out of array size elements? Is it always garbage value or zero?