z6.2-pointers.cc
int usrInt; // User defined int value
int* myPtr = nullptr; // Pointer to the user defined int value
cout << "Enter any number: "; cin >> usrInt; // Prompt user for input
// Output int value and address
cout << "We wrote your number into variable usrInt." << endl;
cout << "The content of usrInt is: " << usrInt << "." << endl;
cout << "usrInt's memory address is: " << &usrInt << "." << endl;
We wrote your number into variable usrInt.
The content of usrInt is: 123.
usrInt's memory address is: 0x7ffe51277304.
cout << endl << "We can store that address into pointer variable myPtr." << endl;
myPtr = &usrInt; // Grab address storing user value
// Output pointer value and value at pointer address
cout << "The content of myPtr is: " << myPtr << "." << endl;
cout << "The content of what myPtr points to is: " << *myPtr << "." << endl;
We can store that address into pointer variable myPtr.
The content of myPtr is: 0x7ffe51277304.
The content of what myPtr points to is: 123.