fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int *ptr = new int (10);
  7.  
  8. cout << "Original value:" << endl;
  9. cout << "*ptr = " << *ptr << endl;
  10.  
  11. delete ptr; //now, the pointer is dangling
  12.  
  13. cout << "After delete:" << endl;
  14. cout << "*ptr = " << *ptr << endl;
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Original value:
*ptr = 10
After delete:
*ptr = 0