Since names
is an array of pointers, it can be computed in the same way as with ages:
int num_names = sizeof(names) / sizeof(char *);
Furthermore, you can do this instead:
int num_names = sizeof(names) / sizeof(*names);
And the same for ages
:
int compte = sizeof(ages) / sizeof(*ages);
If you instead meant the array pointed to by each elements of names
, you can only do so indirectly, like @chezfilou mentions, using strlen
.
Now, if you want to make it easier to deal with, you could use a struct, like so:
struct person {
const char *name;
unsigned age;
} persons[] = {
{.name = "Marie", .age = 35,},
{.name = "Pascale", .age = 38,},
{.name = "Valarie", .age = 42,},
{.name = "Juanita", .age = 48,},
};