struct Point {
int x, y;
};
//C 需要在名称前写 struct 这个词
struct Point p1 = {1, 2};
//p1 is (1, 2)
//初始化时未列出名称的字段为零
struct Point p2 = {.x = 5};
//p2 is (5, 0)
//{} 把每个字段置零;
//没有初始化器时,局部结构体里是垃圾值
struct Point p3 = {};
//p3 is (0, 0)
//没有名称的结构体,仅用于这一个变量
struct {
int top, left;
} p4 = {3, 4};
//p4 is (3, 4)
//typedef 省去了 struct 这个词
typedef struct {
int width, height;
} Size;
Size size = {.height = 20, .width = 10};
//size is (10, 20)
printf("p1 is (%d, %d)\n", p1.x, p1.y);
printf("p2 is (%d, %d)\n", p2.x, p2.y);
printf("p3 is (%d, %d)\n", p3.x, p3.y);
printf("p4 is (%d, %d)\n", p4.top, p4.left);
printf("size is (%d, %d)\n", size.width, size.height);