data-structures · beginner · ~15 min
Map enum values to strings.
Define enum Color { RED, GREEN, BLUE }; and implement const char *color_name(enum Color c) returning "red", "green", or "blue". Return "unknown" for anything else.
enum Color { RED, GREEN, BLUE };
const char *color_name(enum Color c) {
/* TODO */
return "unknown";
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.