学完函数后。我们来尝试一下函数的调用
代码如下:
#include<iostream>
using namespace std;
void swap(int num1, int num2)
{
cout << "交换前" << endl;
cout << "num1=" << num1 << endl;
cout << "num2=" << num2 << endl;
int temp = num1;
num1 = num2;
num2 = temp;
cout << "交换后" << endl;
cout << "num1=" << num1 << endl;
cout << "num2=" << num2 << endl;
}
int main()
{
int a = 10, b = 20;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
swap(
a, b);
cout << "在值传递中,形参的改变不影响实参"<<endl;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
return 0;
}