#include int main(int argc, char** argv) { int size = 10; int c[size]; // Using a variable as the array size is a recent feature // The following is wrong!!! c[20] = 23; // BUG! Array out-of-bounds printf("%d\n",c[20]); // BUG! Array out-of-bounds // The above are bugs! But they may remain silent. // The compiler does not check array bounds. // There are no explicit runtime checks either. // If you are lucky, you will get a segmentation fault // Often, out-of-bounds errors can go undetected for a long time // To avoid bugs, we must remember the size of the array // and always check bounds explicitly // An array is just a group of memory locations int i; for (i = size-1; i >= 0 ; i--) { printf("%p\n",&c[i]); } // The name of the array corresponds to the address of the // beginning of the array printf("Array name: %p\n", c); // Two methods to access and update elements of the array for (i = size-1; i >= 0; i--) { c[i] = 2*i; printf("c[i] is %d ", c[i]); printf("*(c+i) is %d\n", *(c+i)); } // We can create additional pointers to the array int *p = c; printf("Test %d\n", *p); p++; printf("Test %d\n", *p); return 0; }