LISTING8.3 Finding Out What Is Stored in Pointers
1: // Listing 8.3
2: // What is stored in a pointer.
3: #include <iostream>
4:
5: int main()
6: {
7: using namespace std;
8:
9: unsigned short int myAge = 5, yourAge = 10;
10:
11: // a pointer
12: unsigned short int * pAge = &myAge;
13:
14: cout << “myAge:\t” << myAge
15: << “\t\tyourAge:\t” << yourAge << endl;
16:
17: cout << “&myAge:\t” << &myAge
18: << “\t&yourAge:\t” << &yourAge << endl;
19:
20: cout << “pAge:\t” << pAge << endl;
21: cout << “*pAge:\t” << *pAge << endl;
22:
23:
24: cout << “\nReassigning: pAge = &yourAge...” << endl << endl;
25: pAge = &yourAge; // reassign the pointer
26:
27: cout << “myAge:\t” << myAge <<
28: “\t\tyourAge:\t” << yourAge << endl;
29:
30: cout << “&myAge:\t” << &myAge
31: << “\t&yourAge:\t” << &yourAge << endl;
32:
33: cout << “pAge:\t” << pAge << endl;
34: cout << “*pAge:\t” << *pAge << endl;
35:
36: cout << “\n&pAge:\t” << &pAge << endl;
37:
38: return 0;
39: }
myAge: 5 yourAge: 10
&myAge: 0012FF7C &yourAge: 0012FF78
pAge: 0012FF7C
*pAge: 5
Reassigning: pAge = &yourAge...
OUTPUT
230 Day 8