/* * Author: D. Sheets * Description: A BAD BAD PROGRAM!! DON'T LOOK AT THIS PROGRAM! * PLEASE, IT DOES HORRIBLE UNNATURAL THINGS TO ARRAYS! */ #include int main() { int count; /* Array A won't compile, gcc will complain that no size was specified */ // int array_a[]; /* Array B will compile, but it won't actually have any space to store data */ int array_b[0]; int another_variable = 100; /* Array C will also compile, but we going to use the array incorrectly */ int array_c[10]; printf("Size of count is %d\n", sizeof(count)); printf("Size of array_b is %d\n", sizeof(array_b)); for(count=0; count<10; count++) { /* * The first time we try to access array_b we will corrupt data * We may randomly get the runtime error: * "Segmentation fault (core dump)" */ printf("Getting ready to access array_b! another_variable is %d\n", another_variable); array_b[count] = count; printf("I just accessed array_b! Yay! another_variable is %d\n", another_variable); } /* Try to access array_c */ for(count=0; count<20; count++) { array_c[count] += 10; printf("Array C element %d is %d\n", count, array_c[count]); } return(0); }