#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/15 12:55:22
#include void fun(int x) { x=20; } main() { int x=10; fun(x); printf(
x)SK)MIU(LQH++QTV52VUM el u E@4 [Ք<%X-H4BL5 I6IEp ``j0 ̂h؅n'b7 ;!wO~6oΓݽ[=ٱ@,|VϦnxټٌO<ٳe$ΓnݻiP(lΧ3t}wɽOʁiأtYЖg͛!t{铽OY':~9wы3-~,1ZdĩZ\g[MX

#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);
}