Mandrew

Pointer/reference test

Jun 1st, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int *x;
  7.     *x = 10;
  8.     cout << "When int* x = 10:\n";
  9.     cout << x << endl;
  10.     cout << *x << endl;
  11.     cout << &x << endl << endl;
  12.  
  13.     *x = 5;
  14.     cout << "When *x = 5:\n";
  15.     cout << x << endl;
  16.     cout << *x << endl;
  17.     cout << &x << endl << endl;
  18.  
  19.     int q = &x;
  20.     q = 4;
  21.     cout << "When q = &x and q = 4:\n";
  22.     cout << x << endl;
  23.     cout << *x << endl;
  24.     cout << &x << endl << endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment