——- android培训、java培训、期待与您交流! ———-
一、结构数组
数组中每个元素都是相同结构类型的结构变量
定义:
struct student{
int age;
char *name;
}boy[5];
初始化:
struct student stu1[2] = {
{
18,"熊大"},{
17,"熊二"}};//定义数组同时初始化数组;
struct student stu2[2] ;//先定义后初始化
stu2[0] = (struct student){
18,"熊大"};
stu2[1] = (struct student){
17,"熊二"};
二、结构体指针
1、用来存放结构体变量地址的指针变量,将结构体看做是一个普通的变量类型
2、struct 结构体名 * 指针变量名
3、使用结构体指针间接访问结构体的值
1)(*p).age 访问年龄 p中存储的是stu1的地址
2) p->age 访问年龄 (注意:只有在p是结构体指针的时候才能使用)
三、结构体嵌套使用
结构体变量能嵌套其他结构体类型的变量不能嵌套自己的结构体变量,但是可以嵌套指向自己这种类型的指针变量
初始化及访问
struct student{
int age;
char *name;
struct student *banZhang;
};
//初始化
struct student banZhang = {
19,"李班长",NULL};
struct student zhangSan = {
18,"张三",&banZhang};
//访问
printf(