Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int x = 3;
- int temp;
- cout << "The address of x is " << &x << "\n";
- cout << "Input the address of x: ";
- cin >> hex >> temp;
- cout << "The address is " << hex << "0x" << temp << ".\n";
- int *ptr = (int *)temp; // casting "int" to "int pointer"
- cout << "The pointer value is " << *ptr << ".\n";
- cout << "Enter a new value: ";
- cin >> *ptr;
- cout << "The new value of x is " << x << ".\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement