Result of 'sizeof' on array of structs in C?
arrays, c, sizeof, struct
Solution
sizeof a / sizeof a[0];
This is a compile-time constant, so you can use it to, for example, create another array:
#define N sizeof a / sizeof a[0]
int n_a[N];
Problem
In C, I have an array of structs defined like: ``` struct D { char *a; char *b; char *c; }; static struct D a[] = { { "1a", "1b", "1c" }, { "2a", "2b", "2c" } }; ``` I would like to determine the number of elements in the array, but `sizeof(a)` returns an incorrect result: 48, not 2. Am I doing something wrong, or is `sizeof` simply unreliable here? If it matters I'm compiling with GCC 4.4.