Sinux1

T8E1.cpp

Apr 19th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     int x = 777, z = 888;
  8.     int *y;
  9.  
  10.  
  11.     // * = 'the value at
  12.     // & = 'the address of'
  13.  
  14.  
  15.     y = &x; // y equals the address of x
  16.     *y = 500; // This changes the value off x
  17.  
  18.     y = &z; // y equals the address of z (we lost the reference to x)
  19.     *y = 600; // This changes z
  20.  
  21.     cout << x << endl; //The value of x
  22.     cout << y << endl; // This is the address of the variable z
  23.     cout << *y << endl; // This gives us the value that the pointer y is connected to
  24.     return 0;
  25. }
Add Comment
Please, Sign In to add comment