|
- //**************************************************
- //refvalpar.cpp
- //funcion:引用形参和值形参比较实例
- //**************************************************
- #include <cmath>
- #include <iostream>
-
- using namespace std;
-
- void valpara(double); //值形参
- void refpara(double&); //引用形参
-
-
- int main()
- {
- double x1,x2;
- x1=1.0;
- x2=1.0;
-
- valpara(x1);
- refpara(x2);
-
- cout<<"x1="<<x1<<endl;
- cout<<"x2="<<x2<<endl;
-
- char q;
- cin>>q;
- return 0;
- }
-
- void valpara(double x)
- {
- x+=1;
- }
-
- void refpara(double& x)
- {
- x+=1;
- }
-
-
- //运行结果如下:
- //x1=1
- //x2=2
复制代码 |
|