In a book I'm reading, enumeration constants have been introduced before arrays. Use of arrays has been demonstrated only through a couple examples. Following is stated :
enum corvid { magpie, raven, jay, corvid_num};
char const * const bird [ corvid_num ] =
{
[raven] = "raven",
[magpie] = "magpie",
[jay] = "jay",
};
for ( unsigned i = 0; i < corvid_num ; ++i)
printf ("Corvid %u is the %s\n", i, bird[i]);
This declares a new integer type enum corvid for which we know four different values.
Takeaway - Enumeration constants have either an explicit or a positional value
As you might have guessed, positional values start from 0 onward, so in our example we have raven with value 0, magpie with 1, jay with 2, and corvid_num with 3. This last 3 is obviously the 3 we are interested in.
Question 1:
Does [magpie] = "magpie" imply that magpieth position refers to value "magpie".
Question 2:
According to loop, how is bird[0] equal to "raven" , since this is explicit and not a positional value. Also after the first iteration is [i + 1] gonna be equal to [magpie]. In all why is loop variable's type unsigned and not corvid or enum corvid?
I think I have misunderstood enumeration constants.
Also from,
As you might have guessed, positional values start from 0 onward, so in our example we have
ravenwith value 0,magpiewith 1,jaywith 2, andcorvid_numwith 3. This last 3 is obviously the 3 we are interested in.
Is author right to say that raven should have value 0 and not magpie, if this is a typo, entirety of my confusion will dispense.