int main (int argc, char const *argv[])
{
struct date {
int moth;
int day;
int year;
};
struct date today;
today.month = 07;
today.day = 31;
today.year = 2014;
}
声明结构体的形式
1 struct point {
int x;
int y;
};
struct point p1, p2;
p1 和p2 都是point,里面有x和y的值
2 struct {
int x;
int y;
} p1, p2;
p1 和 p2 都是一种无名结构,里面有x和y
3 也是最常见的
struct point {
int x;
int y;
} p1, p2;
p1和p2 都是point,里面有x和y的值
结构数组
struct date dates[100]
含100个struct date的数组
struct date dates[] = {
{4,5,2005}, {2,4,2005}}; 可用dates[i]. 获得每个数组项中的结构成员
note; 结构类型和结构变量时两件事情
结构的初始化
sturct date today = { 07, 31, 2014};
struct date thismonth = { .month =7, .yesr = 2014};