fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int **r = new int *; // declare pointer to int*
  6. cout << r << endl; // outputs some address in memory (pointer to int*)
  7. cout << *r << endl; // outputs some garbage value
  8. // cout << **r << endl; // it's invalid
  9.  
  10. *r = new int; // assign to memory pointed by r new value
  11. cout << *r << endl; // outputs some address in memory (pointer to int)
  12. cout << **r << endl; // outputs some garbage value
  13.  
  14. delete *r; // delete pointer to int
  15. cout << *r << endl; // outputs same address in memory, but we can't dereference it
  16. // cout << **r << endl; // it's invalid, because we deleted *r
  17.  
  18. // here you can acces r, *r, but not
  19. return 0;
  20. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
0x2b2acca84c20
0
0x2b2acca85c50
0
0x2b2acca85c50