早教吧 育儿知识 作业答案 考试题库 百科 知识分享

#include#includestructA{inta;charb[10];doublec;};voidf(structAt);#include#includestructA{inta;charb[10];doublec;};voidf(structAt);main(){structAa={1001,"ZhangDa",1098.0};f(a);pringt("%d,%s,%6.1f\n",a.a,a.b,a.c);}voi

题目详情
#include #include struct A {int a; char b[10];double c;}; void f(struct A t);
#include
#include
struct A
{int a; char b[10];double c;};
void f(struct A t);
main()
{struct A a={1001,"ZhangDa",1098.0};
f(a); pringt("%d,%s,%6.1f\n",a.a,a.b,a.c);
}
void f(struct A t)
{t.a=1002;strcpy(t.b,"ChangRong");t.c=1202.0;}
程序运行后的输出结果是
▼优质解答
答案和解析
f()函数执行的时候,a的值传给t,t被赋值,但是a没变.所以还是输出1001,ZhangDa,1098.0
可以用指针解决
#include “stdio.h”
#include “string.h”
struct A{
\x05int a;
char b[10];
\x05double c;
};
void f(struct A *t);
main(){
\x05struct A a={1001,"ZhangDa",1098.0};
\x05f(&a);
\x05printf("%d,%s,%6.1f\n",a.a,a.b,a.c);
}
void f(struct A *t){
\x05t->a=1002;
\x05strcpy(t->b,"ChangRong");
t->c=1202.0;
}