为什么不是把b 复制到了 c ??
#include <stdio.h>#include <string.h>
typedef struct { char name; char sex; float score; } STU;
void f(STU a)
{
STU b={"Zhao", 'm', 85.0, 90.0};
int i;
strcpy(a.name, b.name);
a.sex = b.sex;
for (i=0; i<2; i++)
a.score = b.score;
}
main()
{
STU c={"Qian", 'f', 95.0, 92.0};
f(c);
printf("%s,%c,%2.0f,%2.0f\n", c.name, c.sex, c.score, c.score);
} 调用函数中,你没有返回值 你改变的只是形参值,可以传指针进去{:10_266:} #include <stdio.h>
#include <string.h>
typedef struct { char name; char sex; float score; } STU;
void f(STU *a)
{
STU b={"Zhao", 'm', 85.0, 90.0};
int i;
strcpy(a->name, b.name);
a->sex = b.sex;
for (i=0; i<2; i++)
a->score = b.score;
}
void main()
{
STU c={"Qian", 'f', 95.0, 92.0};
f(&c);
printf("%s,%c,%2.0f,%2.0f\n", c.name, c.sex, c.score, c.score);
} 迷雾少年 发表于 2016-8-23 11:50
就第十六行变成地址吗? 辣的果丶 发表于 2016-8-23 13:28
就第十六行变成地址吗?
传址
页:
[1]