main()
{
int *p, sum, i;
int x[5] = {5,9,6,3,7};
i = 0;
p = x; /* initializing with base address of x */
printf("Element Value Address\n\n");
while(i < 5)
{
printf(" x[%d] %d %u\n", i, *p, p);
sum = sum + *p; /* accessing array element */
i++, p++; /* incrementing pointer */
}
printf("\n Sum = %d\n", sum);
printf("\n &x[0] = %u\n", &x[0]);
printf("\n p = %u\n", p);
}
Output
Element Value Address
x[0] 5 166
x[1] 9 168
x[2] 6 170
x[3] 3 172
x[4] 7 174
Sum = 55
&x[0] = 166
p = 176