有以下程序 #include #include struct A { int a;char b[10];double c;}; void f(struct A t); main() {structA

admin2017-05-20  35

问题 有以下程序
    #include
    #include
    struct A
    {  int a;char b[10];double c;};
    void f(struct A t);
    main()
    {structA a={1001,"ZhangDa",1098.0};
    f(a);printf("%d,%s,%6.1 f\n",a.a,a.b,a.c);}
    void f(struct A t)
    {t.a=1002;
    strcpy(t.b,"ChangRong");
    t.c=1202.0;}
    程序运行后的输出结果是

选项 A、1 002,ChangRong,1202.0
B、1 00 1,ChangRong,1098.0
C、1001,ZhangDa,1098.0
D、1002,ZhangDa,1202.0

答案C

解析 本题主要考查是的函数调用时参数之间的传递问题。在C语言中参数之间的传递是传值,也就是把实参的值复制一份传递给形参,而实参的值不发生变化。所以对于本题来说,在主函数中执行f(a),把结构体变量a的值复制一份传递给形参变量t,而实参变量a的值保持不变。
转载请注明原文地址:https://kaotiyun.com/show/9ZDp777K
0

最新回复(0)