Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void swap(int *a, int *b) {
- a = b;
- b = a;
- }
- int main() {
- int x1 = 10, x2 = 20;
- cout << "x1 = " << x1 << ", x2 = " << x2 << endl;
- swap(x1, x2);
- cout << "x1 = " << x1 << ", x2 = " << x2 << endl;
- system("pause");
- return 0;
- }
- usung namespace std;
- #include <iostream>
- void swap(int *a, int *b) {
- int temp = *a;
- *a = *b;
- *b = temp;
- }
- int main() {
- int x1 = 10, x2 = 20;
- std::cout << "x1 = " << x1 << ", x2 = " << x2 << std::endl;
- swap(&x1, &x2); // Передаём ссылки
- std::cout << "x1 = " << x1 << ", x2 = " << x2 << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment