As the title said, I just learned about enum (and typedef) in C... and it's pretty freaking cool
take this for example:
#include <stdio.h>
#include <stdlib.h>
typedef enum
{
summer,fall,winter,spring
} season;
void printPhrase(season s);
int main(void)
{
printPhrase(summer);
return 0;
}
void printPhrase(season s)
{
if (s == summer)
printf("It's hot outside\n");
else if (s == fall)
printf("It's getting cooler outside\n");
else if(s == winter)
printf("It's fn cold out\n");
else if(s == spring)
printf("it's getting warmer\n");
else
printf("I have no idea what you're talking about ;)");
}
Now correct me if I'm wrong, but this is my understanding of the code above. Create a variable type named season that is an enum. Inside that variable type season, you can have 4 options (similar to a const char can only be one letter/symbol) summer, fall, winter and spring.
Then there is the prototype for the function printPhrase which takes a variable of the type "season" which we just defined above.
Skipping down to the actual printPhrase function it takes the argument and stores it into "s". Next it compares it to the contents that "season" has (summer, winter, fall, spring). If it equals one of the "seasons" or it is a valid season, then printf a phrase.
As I said before, I just learned this and I might be lacking in some areas so if you see a fault in my explanation, please clarify
One thing I'm kind of shaky on is the contents of the enum... there is no ";" after it, those uninitialized "variables" if that is what you'd call them, look so naked in this explicit C language.