【学习笔记】【C语言】结构体的嵌套

本文介绍了一个使用C语言中结构体进行复杂数据类型定义及初始化的例子。具体展示了如何定义包含多个结构体成员的复合结构体,并通过直接初始化的方式为结构体成员赋值。
 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     struct Date
 6     {
 7         int year;
 8         int month;
 9         int day;
10     };
11     
12     
13     // 类型
14     struct Student
15     {
16         int no; // 学号
17         
18         struct Date birthday; // 生日
19         
20         struct Date ruxueDate; // 入学日期
21         
22         // 这种写法是错误的
23         //struct Student stu;
24     };
25     
26     
27     struct Student stu = {1, {2000, 9, 10}, {2012, 9, 10}};
28     
29     printf("year=%d,month=%d,day=%d\n", stu.birthday.year, stu.birthday.month, stu.birthday.day);
30     
31     
32     
33     
34     
35     return 0;
36 }

 

 

转载于:https://www.cnblogs.com/dssf/p/4608851.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值