|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
结构体:
为什么会出现结构体?
为了表示一些复杂的数据,而普通数据的基本类型变量无法满足要求
什么叫结构体?
结构体是用户根据实际需要自己定义的复合数据类型
- #include<stdio.h>
- #include<string.h>
- struct Student
- {
- int id;
- char name[200];
- int age;
- };
- int main()
- {
- struct Student std={1000,"zhangsan",20};
- printf("%d",std.age);
- //std.name="julia"; //error
- strcpy(std.name,"julia");
- return 0;
- }
复制代码
- #include<stdio.h>
- struct Student
- {
- int id;
- char name[200];
- int age;
- };
- int main()
- {
- struct Student st={1000,"zhangshan",20};
- struct Student *pst;
- pst=&st;
- pst->id=99; //pst->id等价于(*pst).id
-
- return 0;
- }
复制代码
注意事项:
结构体变量不能加减乘除,但可以赋值
普通结构体变量和结构体指针变量作为函数传参的问题
动态内存的分配和释放
|
|