Why is the following code works (printf()
gets executed) before i
reaches 14
? Actually, the execution should fail when i
goes past the 10th element of the array, no? Even I I write:
for(i=0; i<100; i++)
I still get a Segmentation fault of course but all values are printed.
#include <stdio.h>
void funcX() {
int i;
int array[10];
printf("\tEntering funcX()\n");
//for(i=0; i<11; i++) { //This works
//for(i=0; i<12; i++) { //This works
//for(i=0; i<13; i++) { //This works
for(i=0; i<14; i++) { //***This fails****
array[i]=i;
printf( "array[i]= %d\n", array[i] );
}
printf("\tLeaving funcX()\n");
}
int main(int argc, char** argv) {
printf("Calling funcX() from main()\n");
funcX();
printf("Returning from funcX()\n");
return(0);
}
Compiled on RH Linux using gcc -m32
.