Result of 'sizeof' on array of structs in C?
sizeof
returns the size in memory of the passed element. By dividing the size of an array by a single element size, you get the elements count.
Note that the element size may include some padding bytes as well. For this reason, a padded struct (e.g. when a char member is followed by a pointer) will have a sizeof
value greater than it members size sum.
On the other hand, don't let it bother you when counting elements in an array: sizeof(a) / sizeof(a[0])
will still work as smooth as expected.