Guest User

Untitled

a guest
Jun 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void swap(int *a, int *b) {
  6. a = b;
  7. b = a;
  8. }
  9.  
  10. int main() {
  11.  
  12. int x1 = 10, x2 = 20;
  13. cout << "x1 = " << x1 << ", x2 = " << x2 << endl;
  14. swap(x1, x2);
  15. cout << "x1 = " << x1 << ", x2 = " << x2 << endl;
  16.  
  17. system("pause");
  18. return 0;
  19. }
  20.  
  21. usung namespace std;
  22.  
  23. #include <iostream>
  24.  
  25. void swap(int *a, int *b) {
  26. int temp = *a;
  27. *a = *b;
  28. *b = temp;
  29. }
  30.  
  31. int main() {
  32. int x1 = 10, x2 = 20;
  33. std::cout << "x1 = " << x1 << ", x2 = " << x2 << std::endl;
  34. swap(&x1, &x2); // Передаём ссылки
  35. std::cout << "x1 = " << x1 << ", x2 = " << x2 << std::endl;
  36.  
  37. return 0;
  38. }
Add Comment
Please, Sign In to add comment