C语言结构体定义

 时间:2024-10-17 07:19:32

1、 最标准的方式:#include <stdio.h> struct student //结构体类型的说明与定义分开。 声明{int age; /*杏揉动减年龄*/float score; /*分数*/char sex; /*性别*/};int main (){struct student a={ 20,79,'f'}; //定义printf("年龄:%d 分数:%.2f 性别:%c\n", a.age, a.score, a.sex );return 0;}

C语言结构体定义

2、 不环保的方式#include <stdio.h>struct student /*声明时直接定义*/{int age; /*年龄*/float score; /*分数*/char sex; /*性别*//*这种方式不环保,只能用一次*/} a={21,80,'n'};int main (){printf("年龄:%d 分数:%.2f 性别:%c\n", a.age, a.score, a.sex ); return 0;}

C语言结构体定义

3、最奈何人的方式#include <stdio.h> struct //直接定义结构体变量,没有结构体类型名。 这种方式最烂{int age;float score;char sex;} t={21,79,'f'}; int main (){printf("年龄:%d 分数:%f 性别:%c\n", t.age, t.score, t.sex); return 0;}

  • 脑筋急转弯达人Lv4科学怪人第252-257关攻略
  • 微博国际版怎么添加新账号
  • 如何改变微信添加我的途径
  • 马上要开学了,面对疫情怎么办?
  • 补脑明目美食——三文鱼胡萝卜小白菜粥
  • 热门搜索
    如何让头发长 湖北荆州旅游 吉林省旅游景点大全 小米怎么连接电脑 手机忘记解锁图案怎么办 退税申请怎么写 驾照到期如何换新证 膀胱经不通怎么办 梦幻西游无底洞怎么样 电脑加密码怎么设置