I have a struct defined as:
struct smth
{
char a;
int b[];
};
When I call sizeof
and offsetof
on this struct:
cout << sizeof(struct smth) << endl;
cout << offsetof(struct smth, b) << endl;
Output is:
4
4
How come when the size of the stuct is 4 and char is using 1 byte, the offset of the int array is 4? Why is there some kind of padding? Also, why isn't the int array occupying any space at all?
offsetof(struct smth, b)
, right? – Fraught