c结构体

来源:互联网 发布:好吃的零食 知乎 编辑:程序博客网 时间:2024/06/09 20:25
# include <stdio.h>
struct Student{
int age;
char name[100];
int id;
};//注意分号一定不能丢


int main(){
struct Student st={20,"yangyang",10086};
printf("%d %s %d\n",st.age,st.name,st.id);


结构体类似于java里的类 但是不能定义方法 结尾要加分号

结构体不是变量 是数据类型 所以struct Student要写在一起代表的是一种数据类型  

struct Student st代表定义struct Student类型的变量st