Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int x = 777, z = 888;
- int *y;
- // * = 'the value at
- // & = 'the address of'
- y = &x; // y equals the address of x
- *y = 500; // This changes the value off x
- y = &z; // y equals the address of z (we lost the reference to x)
- *y = 600; // This changes z
- cout << x << endl; //The value of x
- cout << y << endl; // This is the address of the variable z
- cout << *y << endl; // This gives us the value that the pointer y is connected to
- return 0;
- }
Add Comment
Please, Sign In to add comment