Advertisement
rfmonk

pointers

Nov 16th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. /*
  5. Use pointers to the heap as opposed to a stack.
  6. Change the value of x and y around
  7.  
  8.  
  9. */
  10.  
  11.  
  12. using namespace std;
  13.  
  14. int main (int argc, char *argv[])
  15. {
  16.     int x = 10;
  17.     int y = 459;
  18.    
  19.     int * pX = &x;
  20.     int * pY = &y;
  21.    
  22.     int TEMP = *pX;
  23.     *pX = *pY;
  24.     *pY = TEMP;
  25.    
  26.     cout << "\n\t Value of x" << *pX;
  27.     cout << "\n\t Value of y" << *pY;
  28.    
  29.     //cout << "\n\n\tValue of px without DEREFERENCE: " << pX;
  30.     //cout << "\n\n\tValue of px with DEREFERENCE: " << *pX;
  31.    
  32.     cout << "\n\n\t";
  33.    
  34.     return EXIT_SUCCESS;
  35.    
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement