- //定义结构体
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- struct PERSON
- {
- int age;
- int height;
- char name[15];
- }p1;
- //={20, 180, "无机盐"};
- //struct PERSON p1=20, 180, "王将诶"}
- p1.age = 23;
- p1.height = 190;
- strcpy(p1.name,"王将诶");
- printf("%d,%d,%s",p1.age,p1.height,p1.name);
- /*
- int age[5];
- int height[5];
- char name[5][10];
- */
- return 0;
- }
- //匿名定义,只能在结构体结尾定义,例如
- /*
- struct
- {
- 成员名
- }结构体变量名;
- */
- /*
- struct 结构体名称
- {
- };
- struct 结构体名称 结构体变量名;
- */
- //该片段来自于http://www.codesnippet.cn/detail/0806201512796.html
来源: http://www.codesnippet.cn/detail/0806201512796.html