#include<stdio.h>
void test(int &x){
x = 1024;
printf("test函数内部 x = %d\n",x);
}
int main(){
int x = 1;
printf("调用前test前 x=%d\n",x);
test(x);
printf("调用test后 x = %d\n",x);
}
本文详细介绍了一个C/C++编程示例,探讨了test函数如何通过引用修改全局变量x。首先展示了程序代码,然后逐步解析其运行过程,揭示了函数作用域与参数传递的重要性。
#include<stdio.h>
void test(int &x){
x = 1024;
printf("test函数内部 x = %d\n",x);
}
int main(){
int x = 1;
printf("调用前test前 x=%d\n",x);
test(x);
printf("调用test后 x = %d\n",x);
}

被折叠的 条评论
为什么被折叠?