Advertisement
35657

Untitled

Apr 5th, 2024
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Swap1(int* a, int* b) {
  6.     int temp = *a;
  7.     *a = *b;
  8.     *b = temp;
  9. }
  10.  
  11. void Swap2(int& a, int& b) {
  12.     int temp = a;
  13.     a = b;
  14.     b = temp;
  15. }
  16.  
  17. int main() {
  18.     setlocale(LC_ALL, "ru");
  19.  
  20.     int a = 5, b = 10;
  21.  
  22.     cout << a << " " << b << endl;
  23.     Swap1(&a, &b);
  24.     cout << a << " " << b << endl;
  25.     Swap2(a, b);
  26.     cout << a << " " << b << endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement