一:

C语言中的struct可以看作变量的集合

example:——————————————————————————————

空结构体占多大内存?

struct TS                  ---------------------------------->          sizeof(struct TS) = ?

{

};

——————————————————————————————————

二:

C语言中的struct分析

C语言中的struct分析

三:

结构体与柔性数组

—— C语言中可以由结构图产生柔性数组

—— C语言中结构体的最后一个元素可以使大小未知的数组

example:———————————————————————————————————————

             struct SoftArray                  ---------------------------------->          sizeof(struct SoftArray) = ?

            {

                        int len;

                        int array[];

            };

注: SoftArray 中的array仅是一个待使用的标识符,不占用存储空间

———————————————————————————————————————————

四:

C语言中的struct分析

C语言中的struct分析

五:

柔性数组的用法:———————————————————————————————————

             struct SoftArray                  ---------------------------------->          sizeof(struct SoftArray) = ?

            {

                        int len;

                        int array[];

            };

            struct SoftArray* sa = NULL;

            sa = (struct SoftArray*)malloc(sizeof(struct SoftArray) + sizeof(int) * 5);

            sa->len = 5;

C语言中的struct分析

———————————————————————————————————————————

六:

C语言中的struct分析

C语言中的struct分析

C语言中的struct分析

 

相关文章:

  • 2022-12-23
  • 2021-09-14
  • 2021-04-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2022-02-26
  • 2021-05-21
猜你喜欢
  • 2021-09-06
  • 2022-12-23
  • 2021-10-16
  • 2018-06-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案