无构造函数

类型初始化 / 结构体

typedef struct {
    int width, height;
} Size;

typedef struct {
    int top, left;
} Point;

typedef struct {
    Size size;
    Point point;
} Rectangle;

//C has no constructors: the fields get values from an initializer list
Rectangle rect = {{10, 10}, {5, 5}};

//or by field names in any order; the fields left out are zero
Rectangle other = {.point = {.left = 5}, .size = {.width = 20, .height = 10}};
//other.point.top is 0

//{} sets every field to zero (C23)
Rectangle empty = {};

printf("rect.size.height is %d\n", rect.size.height);
printf("other.size.width is %d\n", other.size.width);
printf("other.point.top is %d\n", other.point.top);
printf("empty.size.width is %d\n", empty.size.width);