文章
17
粉丝
111
获赞
17
访问
17.1k
一、结构体的定义和使用
1.定义 struct 结构名{成员列表 类型说明符 成员名;};
(1)先定义结构,再说明结构变量struct stu{...}; struct stu boy1,boy2;
宏定义#define STU struct stu STU{...}; STU boy1,boy2;
(2)在定义结构类型同时说明结构变量struct 结构名{成员列表}变量列表名;
struct stu {...}boy1,boy2;
(3)直接说明结构变量 struct{成员列表}变量列表名;
struct{...}boy1,boy2;
2.结构变量成员的表示方法 结构变量名.成员名
3.结构变量赋值
#include <stdio.h>
int main(){
struct stu{
int num;
char *name;
char sex;
float score;
}boy1,boy2;
boy1.num=102;
boy1.name="Zhang ping";
printf("input sex and score\n");
scanf("%c %f",&boy1.sex,&boy1.score);
boy2=boy1;
printf("%d\n%\n",boy2.num,boy2.name);
printf("%c\n%f\n",boy2.sex,boy2.score);
return 0;
}
4.结构变量的初始化
#include <stdio.h>
int main(){
stru...
登录后发布评论
暂无评论,来抢沙发