// Example 710: 2 ways to access data from the array
// (pointer constant) 把「陣列名稱」當作「指標常數」來運作
// operation of the array
#include <stdio.h>
#include <stdlib.h>
int main()
{
int array[] = {11, 22, 33, 44, 55};
int i;
// %p to access address
printf("array = %p \t address = %p\n", array, &array);
printf("\n");
printf("-----------------------------------------\n");
printf("\n");
// access the address (%p)
// method 1: using "&" to access the array[i]'s address
// method 2: {array + index}, array keeps staying array[0]
for(i=0 ; i<5 ; i++){
printf("&array[%d]=%p \t array+%d = %p\n", i, &array[i], i, array+i);
}
printf("\n");
printf("-----------------------------------------\n");
printf("\n");
// access the value (%d)
// method 1: using *(&array[i]), *(address)
// method 2: using *(array+index) to access the array[i]'s value
for(i=0 ; i<5 ; i++){
printf("*(&array[%d])=%d \t *array[%d] = %d\n", i, *(&array[i]), i, *(array+i));
}
printf("\n");
system("pause");
return 0;
}