int main(){struct STU a={"YangSan",2041),b={"WangYin",2043};func1(a);func2(&b);printf ("%d %d n",a.num,b.num)}}
时间: 2024-03-23 19:39:37 浏览: 69
2016秋C程序设计期末试卷(A)1
这段代码看起来有些问题,首先是结构体定义中的逗号应该是分号,应该改为:
```
int main() {
struct STU a = {"YangSan", 2041};
struct STU b = {"WangYin", 2043};
func1(a);
func2(&b);
printf("%d %d\n", a.num, b.num);
return 0;
}
```
然后是函数名,应该是`func1`和`func2`,而不是`1`和`2`,同时函数的定义也需要调整,应该是:
```
void func1(struct STU c) {
struct STU b = {"LiSiGoo", 2042};
c = b;
}
void func2(struct STU *c) {
struct STU b = {"SunDan", 2044};
*c = b;
}
```
最终的代码应该是这样的:
```
#include <stdio.h>
struct STU {
char name[10];
int num;
};
void func1(struct STU c) {
struct STU b = {"LiSiGoo", 2042};
c = b;
}
void func2(struct STU *c) {
struct STU b = {"SunDan", 2044};
*c = b;
}
int main() {
struct STU a = {"YangSan", 2041};
struct STU b = {"WangYin", 2043};
func1(a);
func2(&b);
printf("%d %d\n", a.num, b.num);
return 0;
}
```
输出结果应该是:
```
2043 2044
```
希望能为您提供帮助。
阅读全文