// Project pointers.cpp // Show how to use pointers // for primitive variables. #include #include int main() { // x, p, and q are all automatically // allocated on the stack. int x; int *p = &x; int *q; x = 5; cout << x << " " << &x << " "; cout << p << " " << *p << " "; cout << &p << endl; q = p; *q = 7; cout << x << " " << &x << " "; cout << p << " " << *p << " "; cout << q << " " << *q << endl; cout << &p << " " << &q << endl; // Create dynamic memory on the heap. p = new int; *p = 9; cout << p << " " << *p << " " << &p << endl; return EXIT_SUCCESS; } // Output: 5 0x0012FF7C 0x0012FF7C 5 0x0012FF78 7 0x0012FF7C 0x0012FF7C 7 0x0012FF7C 7 0x0012FF78 0x0012FF74 0x00301B80 9 0x0012FF78