Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int x = 3;
  7. int temp;
  8. cout << "The address of x is " << &x << "\n";
  9. cout << "Input the address of x: ";
  10. cin >> hex >> temp;
  11. cout << "The address is " << hex << "0x" << temp << ".\n";
  12. int *ptr = (int *)temp; // casting "int" to "int pointer"
  13. cout << "The pointer value is " << *ptr << ".\n";
  14. cout << "Enter a new value: ";
  15. cin >> *ptr;
  16. cout << "The new value of x is " << x << ".\n";
  17. return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement