fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3.  
  4. using namespace std;
  5.  
  6. int i;
  7.  
  8. class A{
  9. public:
  10. ~A(){i=10;}
  11. };
  12.  
  13. int& func1()
  14. {
  15. i=3;
  16. A Ob; // -> here local object , hence created and destroyed
  17. return i;
  18. }
  19.  
  20. int& func2()
  21. {
  22. i=8;
  23. A obj;
  24. return i;
  25. }
  26.  
  27. int func3()
  28. {
  29. i=8;
  30. {A obj;}
  31. return i;
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38. int main()
  39. {
  40.  
  41. cout << "i : " <<func1() << endl;
  42. cout << "i : " <<func2() << endl;
  43. cout << "i : " <<func3() << endl;
  44. return(0);
  45. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
i : 10
i : 10
i : 10