fork download
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5. int x = 20;
  6. std::cout << " x = " << x << '\n';
  7.  
  8. int* p = &x;
  9. *p = 10;
  10. std::cout << " x = " << x << '\n';
  11. std::cout << "*p = " << *p << '\n';
  12.  
  13. p = new int;
  14. *p = -100;
  15. std::cout << " x = " << x << '\n';
  16. std::cout << "*p = " << *p << '\n';
  17.  
  18. *p = 25;
  19. std::cout << " x = " << x << '\n';
  20. std::cout << "*p = " << *p << '\n';
  21. delete p; //NEVER forget to delete allocated memory
  22. std::cin.ignore();
  23. std::cin.get();
  24. }
  25.  
Success #stdin #stdout 0s 3432KB
stdin
aa
stdout
 x = 20
 x = 10
*p = 10
 x = 10
*p = -100
 x = 10
*p = 25