enum defines named integer constants. typedef creates an alias for an existing type—improving readability for structs and function pointers.
enum example
enum Color { RED, GREEN, BLUE };
enum Color c = GREEN;
Enumerators increase by default from 0 unless specified. C does not enforce enum type safety as strictly as some languages.
typedef with struct
typedef struct {
int width;
int height;
} Rect;
Now use Rect r; instead of struct Rect r;.
Important interview questions and answers
- Q: enum underlying type?
A: Implementation-defined compatible integer type—oftenint. - Q: typedef vs #define?
A: typedef creates a type alias checked by the compiler; macros are text substitution.
Self-check
- What value does the first enum member get by default?
- Why typedef a struct name?
Interview prep
- typedef benefit?
Creates readable aliases for complex types—especially struct and function pointer types.