<分区>
我编译了这段代码:
// Example program
#include <iostream>
using namespace std;
struct A
{
char a;
};
struct B
{
char b;
int a;
};
struct C
{
int * a;
unsigned char b;
};
int main()
{
cout<< "size of Strcut A:\t"<< sizeof(A)<<endl;
cout<< "size of Strcut B:\t"<< sizeof(B)<<endl;
cout<< "size of Strcut C:\t"<< sizeof(C)<<endl;
cout<< "size of int* : \t"<< sizeof(int*)<<endl;
return 0;
}
我得到了这个结果:
size of Strcut A: 1
size of Strcut B: 8
size of Strcut C: 16
size of int* : 8
现在我想问为什么Strcut B的大小不是5?为什么Struct C的大小不是9? 当内存在嵌入式系统中很重要时,我应该如何在其他平台(如 ARM)中节省内存?