// 24T3 COMP1511 Week 5 Lecture 2 // A demonstration to show how arrays are stored in memory #include #define MAX_LEN 5 void print_array(int *nums, int length); int main(void) { int array[MAX_LEN] = {9, 2, 3}; // array is the name of a block of memory // array is not a pointer variable and we can't change where it points to // but the name of the array decays to pointer to the first element printf("array address: %p\n", array); int i = 0; while (i < MAX_LEN) { printf("Address of array[%d] = %p\n", i, &array[i]); i++; } print_array(array, MAX_LEN); return 0; } // Can pass in array to function with pointer prototype // Can use array indexes with pointers void print_array(int *nums, int length) { printf("address of array in print_array: %p\n", nums); for (int i = 0; i < length; i++) { printf("%d\n", nums[i]); } }