sizeof
's results are compile time constant as a the size of a variable or structure does not change during run-time.
The only exception to this are V(ariable)L(ength)Arrays for which the code defnding them "knows" the size.
Referring:
we can have dynamically allocated array in a structure
So let's assume:
struct s
{
size_t size;
int * ints;
}
The size is sizeof(struct s)
. That is the sum of
- the size of an unsigned interger:
sizeof(size_t)
- the size of a pointer to
int
: sizeof (int *)
- some optional padding bytes
This is independed of to how many bytes the structure's member int * ints
may point.