#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/23 00:55:09
#includevoidfun(intx){x=20;}main(){intx=10;fun(x);printf("x=%d\n",x);}#includevoidfun(intx){x=20;}ma
#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);
}