有以下程序 # include <stdio.h> # include <string.h> Struct A { int a; char b[10]; double c;}; struct A f(struct A t); main() { struc

admin2020-07-28  31

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

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

答案B

解析 在主函数中定义结构体A的变量a,并对其赋初值,再调用函数f(a),在函数f(a)中对结构体变量a的各个成员重新进行了赋值操作,并把其值返回在屏幕上输出。
转载请注明原文地址:https://kaotiyun.com/show/z13p777K
0

最新回复(0)