fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Object {
  5. int somedata;
  6. };
  7.  
  8. Object** globalPtrToPtr; // This is into another area called "data segment", could be heap or stack
  9.  
  10. void function() {
  11. Object* pointerOnTheStack = new Object;
  12. globalPtrToPtr = &pointerOnTheStack;
  13. cout << "*globalPtrToPtr = " << *globalPtrToPtr << endl;
  14. }
  15.  
  16. int main() {
  17. // This can give an access violation, a different value after the pointer destruction
  18. // or even the same value as before, randomly - Undefined Behavior
  19. cout << "*globalPtrToPtr = " << *globalPtrToPtr << endl;
  20. return 0;
  21. }
Runtime error #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty