//
// main.c
// C语言学习 #include <stdio.h> int main(int argc, const charchar * argv[]) { //定义结构体类型 struct Person { charchar *name; int age; double heigth; }; //初始化的4种方式 //1.定义的同时初始化 struct Person p1 = {"zhangsan",20,170}; //2.先定义再逐个初始化 struct Person p2; p2.name = "ykd"; p2.age = 18; p2.heigth = 180; //3.指定将数据赋值给指定的属性 struct Person p4 = {.heigth=1.77, .name="wangwu", .age=33}; //如何从结构体中取数据? printf("name=%s,age=%i,heigth=%f\n",p4.name,p4.age,p4.heigth); //name=wangwu,age=33,heigth=1.770000 return 0;
}