C++ 数据的引用
没啥好说的,直接上代码吧。
1 #include<stdio.h> 2 3 void test1(int x) { 4 5 x = 1024; 6 printf("test函数内部 x=%d\n",x); 7 } 8 //不调用引用 9 void test2(int & x) { 10 11 x = 1024; 12 printf("test函数内部 x=%d\n",x); 13 } 14 //调用引用 15 16 int main(){ 17 int x = 1; 18 printf("调用test1前 x=%d\n",x); 19 test1(x); 20 printf("调用test1后 x=%d\n\n",x); 21 22 printf("调用test2前 x=%d\n",x); 23 test2(x); 24 printf("调用test2后 x=%d\n\n",x); 25 }
有啥不明白的可以评论一下。