1. int a : 传值参数
仅仅将实参的值传递给形参。
#include <bits/stdc++.h>
using namespace std;
void test01(int x)
{
x = 100;
cout<<"x: "<<x<<endl;
cout<<"&x: "<<&x<<endl;
}
int main()
{
int n1 = 7;
test01(n1);
cout<<"n1: "<<n1<<endl;
cout<<"&n1: "<<&n1<<endl;
return 0;
}
输出:
由以上可知:
2. int& a : 传引用参数
将实参取个别名,直接传给形参。
#include <bits/stdc++.h>
using namespace std;
void test01(int& x)
{
x = 100;
cout<<"x: "<<x<<endl;
cout<<"&x: "