Codino Codino - 8 months ago 66
C Question

What does struct_type[1] mean?

I face a code that the old guy get the size of struct like this:

sizeof(struct struct_type[1]);

I tested and it does return the size of struct.

And the

sizeof(struct struct_type[2]);

return the double of struct size.


is not an array, it likes this

struct struct_type {
int a;
int b;

What does it really mean ?


Remember sizeof syntax:

sizeof ( typename );

Here typename is struct struct_type[N] or in more readable form struct struct_type [N] which is an array of N objects of type struct struct_type. As you know array size is the size of one element multiplied by the total number of elements.