I compiled this code:
// 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;
}
And I got this result:
size of Strcut A: 1
size of Strcut B: 8
size of Strcut C: 16
size of int* : 8
now I want to ask why the size of Strcut B is not 5? why the size of Struct C is not 9? when the memory is importent in Embedded system how I should save memory in another platforms like ARM?