/* * A program demonstrating arrays in C. */ #include // need for printf int main() { int array[10]; int i; int x = 0; // Write the elements of an array for (i = 0; i < 10; i++) { array[i] = i; } // Read from an array for (i = 0; i < 10; i++) { printf("%d ", array[i]); } printf("\n"); // Write past the array results in weirdness printf("x value before writing to array[10]: %d\n", x); //array[10] = 5; // try adding this in to see what it does! printf("x value after writing to array[10]: %d\n", x); // You can use pointer arithmetic to access the elements of an array printf("Array address: %p\n", array); for (i = 0; i < 10; i++) { printf("Array element at address %p: %d\n", array + i, *(array + i)); } }