fork download
  1. /******************************************************************************
  2.  
  3.   Online C++ Compiler.
  4.   Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12. double* foo(double* ptr_a, double*& ptr_b) {
  13. double c = 7.3;
  14. double* ptr_c = &c;
  15.  
  16. std::cout << "4. " << *ptr_a << " " << *ptr_b << std::endl;
  17. std::cout << "5. " << ptr_a << " " << ptr_b << std::endl;
  18. std::cout << "6. " << &ptr_a << " " << &ptr_b << std::endl;
  19.  
  20. *ptr_a = c;
  21.  
  22. ptr_a = ptr_c;
  23. ptr_b = ptr_c;
  24.  
  25. return ptr_c;
  26. }
  27.  
  28. int main() {
  29. double a = 4.1;
  30. double b = 5.6;
  31.  
  32. double* ptr_a = &a;
  33. double* ptr_b = &b;
  34.  
  35. std::cout << "1. " << *ptr_a << " " << *ptr_b << std::endl;
  36. std::cout << "2. " << ptr_a << " " << ptr_b << std::endl;
  37. std::cout << "3. " << &ptr_a << " " << &ptr_b << std::endl;
  38.  
  39. double* ptr_c = foo(ptr_a, ptr_b);
  40.  
  41. std::cout << "7. " << ptr_c << std::endl;
  42.  
  43. std::cout << "8. " << *ptr_a << " " << *ptr_b << std::endl;
  44. std::cout << "9. " << ptr_a << " " << ptr_b << std::endl;
  45. std::cout << "10. " << &ptr_a << " " << &ptr_b << std::endl;
  46. }
  47.  
  48.  
Success #stdin #stdout 0.01s 5396KB
stdin
45
stdout
1. 4.1 5.6
2. 0x7fff71c5f948 0x7fff71c5f950
3. 0x7fff71c5f958 0x7fff71c5f960
4. 4.1 5.6
5. 0x7fff71c5f948 0x7fff71c5f950
6. 0x7fff71c5f908 0x7fff71c5f960
7. 0
8. 7.3 6.95324e-310
9. 0x7fff71c5f948 0x7fff71c5f910
10. 0x7fff71c5f958 0x7fff71c5f960