结构体复合字面量(C99)

发布时间 2023-06-03 11:03:28作者: mcb97605

语法:    (结构类型){初始化列表};

 用法:可为一个结构变量提供多个可供替换的值;

 1 struct book{
 2           char title[20];
 3           char author[20];
 4           float value;
 5 };
 6 
 7 int main()
 8 {
 9     struct book readfirst;
10     int score;
11     scanf("%d",score);
12     if(score>=84)
13     {
14         readfirst=(struct book){"crime and punishment","Fyoder         
15                                             Dostoyevsky",11.25};   
16     }
17     else
18        readfirst=(struct book){"crime and punishment","Fyoder         
19                                             Dostoyevsky",5.99};