使用函数,配合着指针实现数据的交换,萌萌的!
#include <Windows.h>
#include <iostream>
using namespace std;
int swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
return 0;
}
int main() {
int x = 10, y = 100;
swap(&x, &y);
printf_s("x=%d,y=%d\n", x, y);
system("pause");
return 0;
}
配上图: