Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

enums-typedef

Enums and typedef

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Enums and typedef: the syntax, patterns, and safety habits you need before advancing in C.

Teams still ship Enums and typedef in C codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Enums and typedef in contexts like: Kernels, drivers, embedded devices, and performance libraries used by other languages.

Write C in main.c with int main(), click Run on server—the dev runner compiles with cc/gcc -std=c11 and runs the binary; read stderr for compile and linker errors (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

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

  1. Q: enum underlying type?
    A: Implementation-defined compatible integer type—often int.
  2. Q: typedef vs #define?
    A: typedef creates a type alias checked by the compiler; macros are text substitution.

Self-check

  1. What value does the first enum member get by default?
  2. Why typedef a struct name?

Interview prep

typedef benefit?

Creates readable aliases for complex types—especially struct and function pointer types.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • enum size?
  • Anonymous struct?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump