设为首页 加入收藏

TOP

C的结构体函数
2019-06-23 16:06:18 】 浏览:82
Tags:结构 函数
 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 }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇第9章 用户自己建立数据类型 下一篇Linux 信号量之Posix基于内存的信..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目