qfedu-c-level/day13/d1.c

19 lines
482 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 结构体内存分配
#include <stdio.h>
struct stu
{
char sex;
int age;
} lucy;
int main()
{
// 是 8 而不是 5因为结构体内存分配是按照最大的数据类型来分配的
// 即使是 char 类型,也会分配 4 个字节
// 但是如果是数组,就会按照数组的大小来分配
// 例如char name[10],那么就会分配 10 个字节
// 本题中8 = 4 + 4
printf("lucy size: %lu\n", sizeof(lucy));
return 0;
}