fork download
  1. #include <iostream>
  2.  
  3. void passPtrByReference( int*& ptrByRef )
  4. {
  5. ptrByRef = reinterpret_cast<int*>(1) ;
  6. }
  7.  
  8. void passPtrByValue( int* ptrByVal )
  9. {
  10. ptrByVal = reinterpret_cast<int*>(2) ;
  11. }
  12.  
  13. int main()
  14. {
  15. int * ptr = 0 ;
  16. std::cout << ptr << '\n' ;
  17.  
  18. passPtrByReference(ptr) ;
  19. std::cout << ptr << '\n' ;
  20.  
  21. passPtrByValue(ptr) ;
  22. std::cout << ptr << '\n' ;
  23. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
0
0x1
0x1