home *** CD-ROM | disk | FTP | other *** search
- /*
- C++ program that demonstrates pointers to existing variables
- */
-
- #include <iostream.h>
-
- main()
- {
- int x = 10;
- int* px = &x;
- // display x using x and rx
- cout << "x contains " << x << "\n";
- cout << "x contains (using the pointer px) "
- << *px << "\n";
- // alter x and display its value using *px
- x *= 2;
- cout << "x contains (using the pointer px) "
- << *px << "\n";
- // alter *px and display value using x
- *px *= 2;
- cout << "x contains " << x << "\n";
- return 0;
- }
-