Reputation: 3473
I am having one c code. Where i had given an array index as 12.But it is allowing me to initialize the array more to that index instead of giving error for index out of bound. Can any one please explain me y it is happeining.
int vas1[12][12];
vas1[15][15]=0;
int i,j;
for (i = 0; i < 15; i ++)
{
for (j = 0; j < 15; j ++) {
printf("i=%d j=%d vas=%d",i,j,vas1[i][j]);
}
}
printf("Success");
Thanks
Upvotes: 1
Views: 253
Reputation: 182684
C doesn't do bounds checking on array accesses. It simply marks illegal accesses as "undefined behavior" so each implementation can do as it please. Since using C means you know what you're doing, C allows you to shoot yourself in the foot.
In practice, sometimes you will get an error, sometimes not. Sometimes you won't get an error but the client will. Worst case scenario: you won't get an error but the program will behave really weird (variables changing values for no reason etc).
Upvotes: 5