首页 > 代码库 > 指针引用修改

指针引用修改

指针引用修改

 1 #include <iostream>
 2 using namespace std;
 3 void getNumA(int num,int param);
 4 void getNumB(int *num,int param);
 5 int newNum = 100;
 6 int main()
 7 {
 8    getNumA(newNum,10); //传递值
 9    cout<<newNum<<endl;
10     
11    getNumB(&newNum,10); //传递地址,引用的修改
12    cout<<newNum<<endl;
13    
14    return 0;
15 }
16 
17 void getNumA(int num,int param){
18     num = param;
19     return;
20 }
21 
22 void getNumB(int *num,int param){
23     *num = param;
24     return;
25 }
26 
27 /*
28 结果:
29 100
30 10
31 */

 

指针引用修改