1 #include<stdio.h> 2 #include<string.h> 3 struct test 4 { 5 int age; 6 char name[16]; 7 double score; 8 }std1; 9 //结构体函数 10 struct test struct_fun(int age,char *name,double score){ 11 struct test student; 12 student.age=age; 13 //student->name=name; 错误,字符串不能直接赋值,可以初始化 14 //example :char name[16]="hello"; 15 strcpy(student.name,name); 16 student.score=score; 17 18 return student; 19 } 20 void output_fun1(int age,char *name,double score){ 21 std1.age=age; 22 strcpy(std1.name,name); 23 std1.score=score; 24 printf("output_fun1 :n"); 25 printf("age=%d,name=%s,score=%.2fn",std1.age,std1.name,std1.score); 26 } 27 //结构体函数输出 28 void output_fun2(struct test stu){ 29 printf("output_fun2 :n"); 30 printf("age=%d,name=%s,score=%.2f",stu.age,stu.name,stu.score); 31 } 32 33 void main(){ 34 output_fun1(15,"xiaoming",89); 35 36 struct test p=struct_fun(17,"xiaohong",80); 37 output_fun2(p); 38 }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/602948.html