// This program demonstrates that an array decays to a pointer
// This is meant to help you understand how we pass arrays
// and manipulate them in functions
#include <stdio.h>
int main(void) {
int array[5] = {0};
int size = sizeof(array);
for(int i = 0; i < 5; i++) {
// %p is the format specifier for an address (pointer address)
printf("Address of the array[%d] is %p\n", i, &array[i]);
}
printf("The address of the array is: %p\n", );
printf("******************************\n");
// %lu is an unsigned long format specifier - only used here for demo purposes
// you will not need to know it in 1511
printf("Original size of the array is %lu bytes (using sizeof)\n", );
printf("Original size of the array is %lu bytes\n", );
// Passing the array to a function
// Passing the array to a function
// Passing the array and the size of the array to a function
return 0;
}
// This function gets passed an array and prints out size of that array,
// but is it actually printing out the size of the array?
void function_one(int array[]) {
printf("Size of the array in function_one() is %lu bytes\n",
);
}
// This function gets passed a pointer to an int array and prints out size of that array,
// but is it actually printing out the size of the array?
void function_two(int *array) {
printf("Size of the array in function_two() is %lu bytes\n",
);
}
// This function gets passed a pointer to the array and its size and
// prints out size of that array, this time retaining the value
void function_three(int *array, int size) {
printf("Size of the array in function_three() is %d bytes\n", );
}