fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void swap(int*& x, int*& y) {
  6. int *s;
  7. s = x;
  8. x = y;
  9. y = s;
  10. }
  11.  
  12. int main() {
  13. int a, b;
  14. int* pa = &a, *pb = &b;
  15.  
  16. cout << "pa = " << static_cast<void*>(pa) << endl;
  17. cout << "pb = " << static_cast<void*>(pb) << endl;
  18.  
  19. swap(pa, pb);
  20.  
  21. cout << "pa = " << static_cast<void*>(pa) << endl;
  22. cout << "pb = " << static_cast<void*>(pb) << endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
pa = 0xbf9b0df8
pb = 0xbf9b0dfc
pa = 0xbf9b0dfc
pb = 0xbf9b0df8