1#include <iostream>
2
3using namespace std;
4const int MAX = 3;
5
6int main () {
7 int var[MAX] = {10, 100, 200};
8 int *ptr;
9
10 // let us have array address in pointer.
11 ptr = var;
12
13 for (int i = 0; i < MAX; i++) {
14 cout << "Address of var[" << i << "] = ";
15 cout << ptr << endl;
16
17 cout << "Value of var[" << i << "] = ";
18 cout << *ptr << endl;
19
20 // point to the next location
21 ptr++;
22 }
23
24 return 0;
25}
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}