当前位置: 移动技术网 > IT编程>开发语言>C/C++ > C的结构体函数

C的结构体函数

2019年06月23日  | 移动技术网IT编程  | 我要评论

完美少年进化论,雪豹下载地址,周雨馨

 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=%.2f\n",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 }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网