#include <iostream>using namespace std;// 值传递// 定义函数 实现两个数字进行交换函数// 如果函数不需要返回值 voidvoid swap(int num1, int num2) {cout << "交换前的数据 num1 = " << num1 << endl;cout << "交换前的数据 num2 = " << num2 << endl;int temp = num1;num1 = num2;num2 = temp;cout << "交换后的数据 num1 = " << num1 << endl;cout << "交换后的数据 num2 = " << num2 << endl;}int main() {int a = 10;int b = 20;swap(a, b);// 当我们做值传递的时候,函数的形参发生变化,不会影响实参cout << "a = " << a << endl;cout << "b = " << b << endl;return 0;}
