When preparing for a C developer role, you must brush up on more than just syntax. Hiring managers will expect you to have a strong grasp of pointers, memory models and be able to walk them through how you build a performance-conscious design. These C interview questions come directly from technical screens I’ve seen as a recruiter.
In this post, the C interview questions that are provided are mid-level developers that are trying to prove they are capable of writing safe and maintainable C code.

1. What is the difference between calloc() and malloc()?
Answer:
malloc() allocates uninitialized memory, while calloc() allocates zero-initialized memory. calloc() also takes two arguments (number of blocks, size per block) versus malloc()’s single size argument.
2. What is a memory leak, and how do you prevent it in C?
Answer:
A memory leak occurs when allocated memory is not freed, causing gradual memory exhaustion. To prevent it, always pair malloc()/calloc() with free(), avoid overwriting pointers before freeing them, and use tools like Valgrind to detect leaks.
3. Explain the difference between a pointer and an array in C.
Answer:
While arrays and pointers can be used similarly, arrays allocate memory at compile time and can’t be reassigned. Pointers are variables that store memory addresses and can point to different locations at runtime.
4. What is the use of static keyword in C?
Answer:
static restricts the scope of a variable or function to the file or function in which it’s declared. For variables, it also preserves state between function calls.
5. What’s the difference between struct and union?
Answer:
In a struct, each member has its own memory location. In a union, all members share the same memory, and the size of the union equals the size of its largest member. This makes unions useful for memory optimization.
6. How do function pointers work in C?
Answer:
Function pointers store the address of a function and can be used to call functions dynamically. They’re often used for callbacks or implementing function dispatch tables.
7. What are volatile and const used for?
Answer:
volatile tells the compiler not to optimize a variable, as it may change outside the program (e.g., hardware register). const ensures that a variable’s value cannot be modified after initialization.
8. What is undefined behavior in C?
Answer:
Undefined behavior is code that may produce unpredictable results due to violations of the C standard (e.g., out-of-bounds access, integer overflow, using uninitialized variables). Avoiding it is critical to writing reliable software.
9. How is memory allocated and managed in C?
Answer:
Memory in C is divided into stack (for local variables), heap (via malloc()/free()), and static/global memory. Understanding the lifecycle of each is essential for safe C development and comes up frequently in C interview questions.
10. What are the different storage classes in C?
Answer:
The four storage classes are auto, register, static, and extern. They define the scope, visibility, and lifetime of variables.
11. How do you prevent buffer overflows in C?
Answer:
Use functions like snprintf() instead of sprintf(), perform bounds checking manually, and leverage compiler flags like -fstack-protector. Secure coding practices are often tested through C interview questions for system-level roles.
12. What is the difference between == and = in C?
Answer:
= is the assignment operator, and == is the equality comparison operator. Confusing the two can lead to hard-to-find bugs, especially in conditional statements.
13. Can a const variable be modified in any way?
Answer:
Yes, but only through type casting (which is unsafe) or by accessing memory directly. However, doing so leads to undefined behavior. This concept shows up often in C interview questions testing immutability and memory safety.
14. How does recursion work in C, and when should it be avoided?
Answer:
Recursion occurs when a function calls itself. It’s useful for problems like tree traversal or factorials but should be avoided for deep calls due to limited stack space. Iterative solutions are often more efficient.
15. What is the difference between exit() and _exit()?
Answer:
exit() performs cleanup like flushing I/O buffers, calling atexit() handlers, etc. _exit() terminates immediately without cleanup, making it appropriate for child processes after a fork() in UNIX systems.
16. What are some common compiler optimization flags you use when compiling C?
Answer:
Flags like -O2, -O3, -g (debugging), -Wall (enable warnings), and -fstack-protector are frequently used. Tuning these is critical for balancing performance, debugging, and safety.
17. Why are header guards or #pragma once used in C?
Answer:
They prevent multiple inclusions of the same header file, which can cause compilation errors. Either #ifndef/#define/#endif or #pragma once (non-standard but widely supported) is used.
Wrapping Up
For mid-level roles, C interview questions aren’t going to focus only on syntax. Hiring managers are looking for design decisions and how your code can make an impact using best practices. If you’re serious about progressing in your C career, these questions should be second nature. You should be able to walk through code examples to demonstrate them.
Whether you’re getting ready for an embedded systems role, kernel development, or performance-critical backend systems, use these C interview questions as your technical checklist.