I'm confused with how exactly the enum-type variable and int-type variable works different in C.
I heard there could be a casting error between enum type and integer type in C++, but C doesn't.
Then if there's no difference between integer variable and enum type variable in C, can I just declare enum names and use them without declaring any that enum type variables, for example,
...
enum { WIN, LOSE, DRAW };
int main() {
int result;
result = play_game(...);
if (result == WIN) { ... }
else if (result == LOSE) { ... }
...
}
int play_game(...) {
...
if (...) return WIN;
else if (...) return LOSE;
else return DRAW;
...
}
like above. (just for enhancing readability instead of using meaningless numbers; 0
, 1
, 2
, 10
, -1
, etc.)
Actually, I could not understand what is the meaning of declaring specific enum type variable, like below.
enum GameResult { WIN, LOSE, DRAW } result;
Is this also related with the code readability?
I mean, there any difference between declaring result
as int and as enum type variable?