Loading... C语言允许用户自己建立由不同类型数据组成的组合型的数据结构,称为结构体。 <div class="tip inlineBlock info"> struct是声明结构体类型时必须使用的关键字。 结构体在main主函数前声明!!!(并不是说必须在main前面声明,在main里面声明也可以,不过为了简单明了,不被老板开除,结构体写在main主函数的前面) </div> ```cpp #include <stdio.h> struct Student { int num ; char name [ 20 ] ; double score ; }student1 , student2 ; int main ( ) { scanf ( "%d,%s,%lf" , &student1.num , student1.name , &student1.score ) ; scanf ( "%d,%s,%lf" , &student2.num , student2.name , &student2.score ) ; printf ("第一位童鞋的资料为:%d %s %.0f\n" , student1.num , student1.name , student1.score ) ; printf ("第一位童鞋的资料为:%d %s %.0f\n" , student2.num , student2.name , student2.score ) ; } ``` 最后修改:2021 年 05 月 20 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果文章有用,请随意打赏。