fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct foo {
  6. int x;
  7. int* y;
  8. foo(int _x, int _y) : x{_x} {
  9. y = new int(_y);
  10. }
  11. };
  12.  
  13. void print(int step, foo& v) {
  14. cout << step << ". x = " << v.x << " ; y = " << *(v.y) << endl;
  15. }
  16.  
  17. void modify(int step, foo v) {
  18. v.x = 3;
  19. *(v.y) = 4;
  20. print(step, v);
  21. }
  22.  
  23. int main() {
  24. foo v(1, 2);
  25. print(1, v);
  26. modify(2, v);
  27. print(3, v);
  28. return 0;
  29. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
1. x = 1 ; y = 2
2. x = 3 ; y = 4
3. x = 1 ; y = 4