问题描述
- c语言关于结构体的问题
-
typedef struct Data
{
int arr[10];
int* p_low;
int* p_high;
} Data;int main()
{
Data* data = NULL;
printf("%p
",data->arr);
printf("%p
",&(data->arr[1]));
printf("%p
",data->p_low); 为什么程序再这里就 crash 了????
printf("%p
",data->p_high);return 0;
解决方案
知道了,是因为访问了空的指针.
解决方案二:
?C语言中结构体对齐问题 收藏 关于C语言中的结构体对齐问题
1,比如:
struct{short a1;short a2;short a3;}A;struct{long a1;short a2;}B;sizeof( A)=6, sizeof( B)=8,为什么?注:sizeof(short)=2,sizeof(long)=4
因为:“成员对齐有一个重要的条件,即每个......
答案就在这里:C语言中结构体对齐问题
----------------------
解决方案三:
知道了,是因为访问了空的指针.
时间: 2024-07-29 04:12:43