/* Run at CSE like this $ clang -Wno-everything invalid1.c $ ./invalid1 i is at address 0x7fffb1d7bce8 a[0] is at address 0x7fffb1d7bcc0 a[9] is at address 0x7fffb1d7bce4 a[10] would be stored at address 0x7fffb1d7bce8 doesn't terminate If compiling with gcc, change index to 11. */ #include #include int main(void) { int i; int a[10]; printf("i is at address %p\n", &i); printf("a[0] is at address %p\n", &a[0]); printf("a[9] is at address %p\n", &a[9]); printf("a[10] would be stored at address %p\n", &a[10]); // loop writes to a[10] which don't exist - // but on CSE servers (clang 7.0 x86_64/Linux) // i would be stored where a[10] is stored for (i = 0; i <= 10; i++) { printf("%d\n", i); a[i] = 0; } return 0; }