是什么?
1. 内存对齐的定义
struct Example {
char a; // 1字节
int b; // 4字节
char c; // 1字节
};2. 内存对齐的原因
4. 内存对齐的好处
5. 对齐方式
6. 查看内存对齐
7. 总结
Last updated
struct Example {
char a; // 1字节
int b; // 4字节
char c; // 1字节
};Last updated
#include <stdio.h>
struct Example {
char a;
int b;
char c;
};
int main() {
printf("Size of char: %zu\n", sizeof(char));
printf("Size of int: %zu\n", sizeof(int));
printf("Size of Example: %zu\n", sizeof(struct Example));
return 0;
}
// 这里的C放在最后和放在a、b之间是有差别的。