常量

结构体(记录)

//C 没有字段的默认值:
//const 字段只能在初始化时获得值
typedef struct {
    const int lineWidth;
    int length;
} BoldLine;

BoldLine boldLine = {.lineWidth = 10, .length = 100};
//boldLine.lineWidth = 20; //<-Error
int width = boldLine.lineWidth;
//width is 10

//常量结构体用作值的模板
constexpr BoldLine defaultLine = {.lineWidth = 12, .length = 50};
BoldLine line = defaultLine;
//line = defaultLine; //<-Error: const 字段不允许 =
//line.lineWidth is 12

printf("width is %d\n", width);
printf("line.lineWidth is %d\n", line.lineWidth);