← All interview questions

Skill Zuno · skillzunos.com · Fullstack

C Design Patterns interview questions

Prepare for C Design Patterns interviews on Skill Zuno. This practice book covers C Design Patterns interview questions across New, Easy, Medium, Hard, and Diff levels so you can work through real interview-style problems on skillzunos.com.

Open C Design Patterns on Skill Zuno

Also see the C Design Patterns tutorial.

C has no classes or inheritance, so design patterns in C are built from structs, function pointers, opaque pointers and careful ownership rules. Patterns such as opaque types, vtables of function pointers, callbacks and state machines appear throughout the Linux kernel, embedded firmware and C libraries. Interviews test how to get encapsulation and polymorphism from plain C.

Sample C Design Patterns interview questions

How do you get encapsulation in C?

Declare struct foo; in the header and define its fields only in the .c file. Callers hold a foo * and must use the module's functions, so they cannot touch or depend on the internals.

How do you implement polymorphism in C?

Give each type a pointer to a struct of function pointers, a hand-written vtable. Code calls obj->ops->draw(obj) without knowing the concrete type, which is how the Linux kernel's file_operations work.

How is the strategy pattern written in C?

Pass a function pointer for the varying behaviour. qsort() is the classic example: the caller supplies the comparison function and qsort supplies the algorithm.

Why use goto for cleanup in C?

When a function acquires several resources, jumping to cleanup labels in reverse order releases exactly what was acquired on every error path, without deeply nested ifs or duplicated free() calls.

How would you write a state machine in C?

Use an enum for states and either a switch on the current state or a table of function pointers indexed by state and event. The table form makes adding states and transitions easy.

What you can practice

  • C Design Patterns interview questions for beginners and experienced developers
  • Level-based practice: New, Easy, Medium, Hard, and Diff
  • Fullstack topics alongside C Design Patterns on skillzunos.com

More Fullstack interview questions

All interview questions