c语言获取结构体大小sizeof,C语言sizeof求结构体数组长度

C语言sizeof求结构体数组长度

C语言sizeof求结构体数组长度

#include

typedef struct ss{

char a;//偏移量为0,大小为1,0能被1整除,=1

short b;//偏移量为1,大小为2,1不能被2整除,=1+1+2=4

int c;//偏移量为4,大小为4,4能被4整除,=4+4=8

long d;//偏移量为8,大小为4,8能被4整除,=8+4=12

} ss_t;

struct ss s1[]={

{0x1,0x2,0x3,0x4},

{0x5,0x6,0x7,0x8},

{0xa,0xb,0xc,0xd},

};

int s1_len= sizeof(s1)/sizeof(s1[0]);

struct ss s2[]={

{0x1,0x2,0x3,0x4},

{0x5,0x6,0x7,0x8},

{0xa,0xb,0xc,0xd},

{},

};

int s2_len= sizeof(s2)/sizeof(s2[0]);

struct ss s3[]={

{},

{0x1,0x2,0x3,0x4},

{0x5,0x6,0x7,0x8},

{0xa,0xb,0xc,0xd},

};

int s3_len= sizeof(s3)/sizeof(s3[

你可能感兴趣的:(c语言获取结构体大小sizeof,C语言sizeof求结构体数组长度)