Codino Codino - 1 year ago 121
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 ?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download