fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. class Ref
  7. {
  8. int &p;
  9. public:
  10. Ref(int&p):p(p){}
  11. void out() { cout << (void*)&p << endl; }
  12. };
  13.  
  14. class Val
  15. {
  16. int p;
  17. public:
  18. Val(int&p):p(p){}
  19. void out() { cout << (void*)&p << endl; }
  20. };
  21.  
  22.  
  23. int main(int argc, char * argv[])
  24. {
  25. int x = 5;
  26. cout << (void*)&x << endl;
  27. Ref r(x);
  28. Val v(x);
  29. r.out();
  30. v.out();
  31. }
  32.  
Success #stdin #stdout 0.01s 5528KB
stdin
Standard input is empty
stdout
0x7ffe281ce910
0x7ffe281ce910
0x7ffe281ce914