结构体初始化与基本操作.pptVIP

  • 2
  • 0
  • 约4.19千字
  • 约 15页
  • 2019-04-19 发布于湖北
  • 举报
结构体的初始化与基本操作 C语言中的结构体的定义方法如下: Struct date {?int year ; int month ; Int day ; } ;(注意最后的分号不能省略)。 其中第一行的“date”是该结构体的名称, 花括号里面的内容是结构体的成员名,这是声明结构体的一般形式 定义结构体变量方法1: Struct date {?int year ; int month ; Int day ; } ; struct date birthday; Birthday.year // 引用成员 定义结构体变量方法2: Struct date {?int year ; int month ; Int day ; } birthday ; 例:用结构描述一个人的基本情况。 struct person /* 定义person结构类型 */ { char name [30]; char sex; struct date birth;/* 结构的嵌套定义 */ } tman; // :1984年7月28日出生的先生: tman.sex=“M”; tman.birth.year=1984; tman.birth.month=7; tman.birth.day=28; 例2:输入今天的日期,然后输出该日期。 #include stdio.h main

文档评论(0)

1亿VIP精品文档

相关文档