1#include <stdio.h>
2
3const int MAX = 3;
4
5int main () {
6
7 int var[] = {10, 100, 200};
8 int i, *ptr;
9
10 /* let us have array address in pointer */
11 ptr = &var[MAX-1];
12
13 for ( i = MAX; i > 0; i--) {
14
15 printf("Address of var[%d] = %x\n", i-1, ptr );
16 printf("Value of var[%d] = %d\n", i-1, *ptr );
17
18 /* move to the previous location */
19 ptr--;
20 }
21
22 return 0;
23}
1#include <stdio.h>
2
3const int MAX = 3;
4
5int main () {
6
7 int var[] = {10, 100, 200};
8 int i, *ptr;
9
10 /* let us have array address in pointer */
11 ptr = var;
12
13 for ( i = 0; i < MAX; i++) {
14
15 printf("Address of var[%d] = %x\n", i, ptr );
16 printf("Value of var[%d] = %d\n", i, *ptr );
17
18 /* move to the next location */
19 ptr++;
20 }
21
22 return 0;
23}
1#include <stdio.h>
2
3const int MAX = 3;
4
5int main () {
6
7 int var[] = {10, 100, 200};
8 int i, *ptr;
9
10 /* let us have address of the first element in pointer */
11 ptr = var;
12 i = 0;
13
14 while ( ptr <= &var[MAX - 1] ) {
15
16 printf("Address of var[%d] = %x\n", i, ptr );
17 printf("Value of var[%d] = %d\n", i, *ptr );
18
19 /* point to the next location */
20 ptr++;
21 i++;
22 }
23
24 return 0;
25}
1Address of var[0] = bf882b30
2Value of var[0] = 10
3Address of var[1] = bf882b34
4Value of var[1] = 100
5Address of var[2] = bf882b38
6Value of var[2] = 200
7