#include void fun(int x) { x=20; } main() { int x=10; fun(x); printf("x=%d\n",x); }#includevoid fun(int x){x=20;}main(){int x=10;fun(x);printf("x=%d\n",x);}

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 00:30:39

#include void fun(int x) { x=20; } main() { int x=10; fun(x); printf("x=%d\n",x); }#includevoid fun(int x){x=20;}main(){int x=10;fun(x);printf("x=%d\n",x);}
#include void fun(int x) { x=20; } main() { int x=10; fun(x); printf("x=%d\n",x); }
#include
void fun(int x)
{
x=20;
}
main()
{
int x=10;
fun(x);
printf("x=%d\n",x);
}

#include void fun(int x) { x=20; } main() { int x=10; fun(x); printf("x=%d\n",x); }#includevoid fun(int x){x=20;}main(){int x=10;fun(x);printf("x=%d\n",x);}
结果仍然为10
c的函数都是值传递的,也就是形参值的改变,不影响实参的值.如果想改变实参的值,可以使用指针.例如下面这样:
#include
void fun(int *x)
{
*x=20;
}
main()
{
int x=10;
fun(&x);
printf("x=%d\n",x);
}