fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int* ptr = new int(2);
  6. int& i = *ptr;
  7. std::cout<<i<<std::endl; //prints 2
  8. ptr = new int(3); //now ptr points to another address
  9. std::cout<<*ptr<<std::endl; //prints 3
  10. std::cout<<i<<std::endl; //still prints 2!
  11. return 0;
  12. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2
3
2