C语言

  1. 结构体数组、

    1. 定义结构体数组

      1. 单独定义、

        1. struct a
          {
          	int m;
          	int	d;
          	int y;
          };
          struct b
          {
          	int xuhao;
          	char ming[];
          	int xingbie;
          	int nianling;
          	char dizhi;
          	struct a rqi;//结构体套结构体、
          };
          
          int main()
          
          {
          	struct b c[5];//单独定义
          
      2. 定义结构时定义

        1. struct a
          {
          	int m;
          	int	d;
          	int y;
          };
          struct b
          {
          	int xuhao;
          	char ming[50];
          	int xingbie;
          	int nianling;
          	char dizhi;
          	struct a rqi;//结构体套结构体、
          }d[5];//全局定义、
          
          
          
      3. 定义时初始化、

        1. 定义时每个元素使用{},间隔

        2. struct b c[5] = {
          		{41,"姓名",1, 23,34},
          		{45,"姓名",1, 25,31},
          		{46,"姓名",1, 20,32},
          	};
          
          
        3. struct b c[5] = {
          		{41,"姓名",1, 23,34},
          		{41,"姓名",1, 20,34},
          		{41,"姓名",1, 27,34},
          	};
          
          	c[1].nianling++;
          	printf("nianling=%d\n", c[1].nianling);
          
  2. 结构体指针、

    1. 结构体变量的指针、指向该结构体变量所占的内存段的起始地址、

    2. 也可以指向结构体数组中的元素、

      1. struct b d;
           	struct b* c;
           	c = &d;
           
           	d.nianling = 29;
           	(*c).nianling = 40;
           	c->nianling = 31;
           
           	printf("ninliang=%d\n", c->nianling);
        
        
        
    3. -> 指向结构体成员运算符、

  3. 用指向结构体的指针做函数参数、

posted on 2020-09-18 21:53  程耀辉  阅读(139)  评论(0编辑  收藏  举报