Answer the question
In order to leave comments, you need to log in
How to use the enum type?
I can't figure it out, I've skimmed through the whole book. Googled. I still didn't understand anything.
Here is an example:
#include <stdio.h>
void main(void) {
enum type {A,B,C} var;
printf("%d\n%d\n%d\n",A,B,C);
printf("\n%d\n",var);
enum type D,E,F;
printf("\n%d\n%d\n%d\n",D,E,F);
system("PAUSE");
}
Answer the question
In order to leave comments, you need to log in
type
-- is the type name of your enum. var
-- the name of the variable of the newly declared type. The code can be rewritten like this:
enum type {
A,B,C
};
enum type var;
type
-- is a key word, classical is better enum fruit { apple, orange };
. Plus, to define variables in the type declaration -- advanced feature, I would not give it in the first example.
In the example D,E,F are not initialized. Garbage is output to the console.
To begin with, you need to throw out the material in which you read this:
When you find the material where it is written:
then you will find out what enum is and so on.
It’s just that if you study from shitty materials, then you can’t learn anything, because the author of the materials himself doesn’t know anything.
There is a good book, the main one in the C world
https://en.wikipedia.org/wiki/The_C_Programming_La...
250 pages where you will find everything you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question