#include<iostream>
using namespace std;
//值传递
//定义函数,实现数字交换
//如果函数不需要返回值,声明时可以写void
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;//此处会输出为num1=??的形式,无法直接输出为实参的名字,不太清楚应该如何直接输出实参名
cout << "num2=" << num2 << endl;
//在函数没有返回值时可以不写return
}
int main() {//主函数返回值为整型
//main函数中调用add函数
int a = 10;
int b = 20;
swap(a, b);//无返回值,直接输出函数
system("pause");//暂停系统命令
return 0;//退出程序
}