1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include <iostream> // 输出流库 using namespace std; // 使用标准命名空间 // 课程:07.3 函数值传递 void test(int num1, int num2) { cout << "交换前的数据" << endl; cout << "nun1 = " << num1 << endl; cout << "nun2 = " << num2 << endl; int temp = num1; num1 = num2; num2 = temp; cout << "交换后的数据" << endl; cout << "nun1 = " << num1 << endl; cout << "nun2 = " << num2 << endl; //return;// 当没有返回值的时候,这一步可省略 } int main() { int a, b; a = 10; b = 25; cout << "a = " << a << endl; cout << "b = " << b << endl; test(a, b); cout << "a = " << a << endl; cout << "b = " << b << endl; //当实参数据传递给形参后, //形参数据发送改变,不会影响到实参 system("pause"); // 控制台暂停,等待下一步操作 return 0; // 结束返回值:0 } |
07.3 C++函数值传递
未经允许不得转载:Ai分享 » 07.3 C++函数值传递