也可以在声明中通过按大括号内的顺序列出初始值来初始化结构变量:
struct student s1 = {19, 9, "John"}; struct student s2 = {22, 10, "Batman"};
如果要在声明后使用大括号初始化结构,还需要键入cast,如以下语句所示:
struct student s1; s1 = (struct student) {19, 9, "John"};
在初始化结构以初始化相应成员时,可以使用命名成员初始化:
struct student s1 = { .grade = 9, .age = 19, .name = "John"};
在上面的示例中,.grade是指结构的grade成员。同样,.age和.name指的是年龄和名称成员。