fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A
  5. {
  6. int& a;
  7. };
  8.  
  9. int main() {
  10. int a = 5;
  11. cout << (void*)&a << ' ';
  12. A* b = nullptr;
  13. {
  14.  
  15. int& c = a;
  16. cout << (void*)&c << ' ';
  17. b = new A{ c };
  18.  
  19. int* d = (int*)((void*)b);
  20. *d = 0;
  21. cout << "ref address: " << (void*)d << ' ';
  22.  
  23. }
  24. cout << (void*)&(b->a) << ' ';
  25.  
  26. // your code goes here
  27. return 0;
  28. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
0xbfb366fc 0xbfb366fc ref address: 0x9807a10 0