赞
踩
仅仅将实参的值传递给形参。
- #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;
- }
-
输出:
由以上可知:
将实参取个别名,直接传给形参。
- #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;
- }
-
输出:
由以上可知:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。