I have just started C very recently and I have been asked to answer some coding exercises in which the following piece of code appears:
typedef enum {
false = 0,
true = 1
} Bool;
Could someone please provide a brief and clear explanation to that?
Thanks very much.
It’s really doing two things; you can break it down something like this:
And:
This code creates a new enumeration type and then uses
typedefto give it a convenient name. It would let you use a new ‘type’ calledBoolelsewhere in your code, and assign it the valuesfalseandtrue. Here’s a simple use case: