Interview questions · Tech stack

C Interview Questions & Answers (2026)

These interviews test your mastery of C fundamentals, memory management, pointer arithmetic, and low‑level system interactions. Demonstrate clear reasoning, explain trade‑offs, and show how you write safe, efficient code. Focus on explaining why a solution works, its complexity, and potential edge cases to impress interviewers.

22 questions · updated Aug 29, 2026

Quick facts

Typical roundsPhone screen, technical coding, system design, and on‑site deep dive
Core topicsPointers, memory allocation, structs, bitwise ops, concurrency
Preferred languagesStandard C (C99/C11), no extensions
Time limit per question15‑30 minutes for coding, 5‑10 minutes for theory

Questions

Beginner

Explain the difference between malloc and calloc.

malloc allocates a block of memory of a given size without initializing its contents, so the memory contains indeterminate values. calloc takes two arguments—the number of elements and the size of each—and returns zero‑filled memory. Interviewers expect you to mention that calloc may have a slight performance overhead due to zeroing, but it prevents bugs from reading uninitialized data. A strong answer also notes that both require free to avoid leaks and that calloc can simplify code when you need a clean buffer.

GoogleMicrosoft

What is a dangling pointer and how can you avoid it?

A dangling pointer points to memory that has been freed or gone out of scope. Accessing it leads to undefined behavior, often crashes. To avoid it, always set pointers to NULL after free, use smart pointer patterns (e.g., wrapper structs), and limit pointer lifetimes by keeping ownership clear. Interviewers look for awareness of both immediate and long‑term safety, such as avoiding double free and ensuring that no other code retains a stale reference.

Amazon

How does the sizeof operator work on arrays and pointers?

sizeof yields the compile‑time size in bytes of its operand. For an array, it returns total bytes (element size × length). For a pointer, it returns the size of the pointer itself (typically 4 or 8 bytes), not the pointed‑to data. Interviewers expect you to illustrate with int arr[10]; sizeof(arr) is 40 (on 32‑bit int), while int *p; sizeof(p) is 8 on a 64‑bit system. This distinction is crucial when passing arrays to functions, where they decay to pointers.

Meta

What is the difference between struct and union?

A struct allocates space for all members, allowing each to hold a value simultaneously. A union shares a single memory region among all members, so only one member holds a valid value at a time. This saves memory but requires careful tracking of the active member. Interviewers look for you to mention use cases like variant types or memory‑efficient protocol parsing, and the need for a discriminator field to avoid undefined behavior.

Cisco

How does pointer arithmetic work with different data types?

When you add an integer n to a pointer p, the address advances by n * sizeof(*p). For int *p, p+1 moves forward 4 bytes (on 32‑bit int). For char *p, p+1 moves one byte. This scaling ensures array indexing works correctly. Interviewers expect you to explain that mixing pointer types without casting can lead to misaligned accesses and that pointer arithmetic is only defined within the same array or one past its end.

Oracle

What are the pitfalls of using gets() and why is it deprecated?

gets reads an entire line without bounds checking, allowing buffer overflow if input exceeds the destination array. This leads to memory corruption and security vulnerabilities. It was removed from C11. Interviewers expect you to recommend fgets with a size argument, and to discuss how proper input validation prevents exploits like stack smashing.

Microsoft

What are the differences between static and extern storage classes?

static limits visibility to the translation unit (file) and retains the variable's value across function calls. extern declares a variable defined elsewhere, allowing cross‑file linkage. For functions, static restricts the function to internal linkage, while extern (the default) gives external linkage. Interviewers expect you to discuss default storage duration, linkage, and typical usage patterns such as encapsulating module‑private globals with static.

Cisco

What is undefined behavior and give an example in C.

Undefined behavior (UB) occurs when the C standard imposes no requirements on the result of executing certain code, allowing compilers to assume it never happens. Example: signed integer overflow, such as int x = INT_MAX; x = x + 1; The result is unpredictable and may be optimized away. Interviewers expect you to stress that UB can lead to security bugs and that writing portable code means avoiding it.

Apple

Intermediate

Describe how you would implement a thread‑safe singleton in C.

Use a static pointer initialized to NULL and protect initialization with a mutex. On first call, lock the mutex, check again if the instance is NULL, allocate and initialize, then unlock. Subsequent calls skip allocation. This double‑checked locking pattern reduces contention. Mention that C11 provides atomic_flag for lock‑free initialization, but a portable solution relies on pthread_mutex. Emphasize avoiding race conditions and ensuring memory visibility across threads.

Netflix

What is memory alignment and why does it matter?

Memory alignment requires that data types be stored at addresses that are multiples of their size or a platform‑specific boundary. Misaligned accesses can cause performance penalties or hardware faults on some architectures. Compilers insert padding to satisfy alignment, which can increase struct size. Interviewers expect you to discuss how aligning structures improves cache efficiency and how to use __attribute__((packed)) cautiously when you need a tightly packed layout.

Intel

Explain the use of volatile keyword.

volatile tells the compiler that a variable may change outside the program flow, such as hardware registers or signal handlers. It prevents optimizations that assume the value remains constant between reads. Interviewers look for you to note that volatile does not guarantee atomicity or ordering; you still need proper synchronization for multithreaded access. A strong answer includes examples like reading a UART status register or a flag set by an ISR.

Qualcomm

How would you detect integer overflow in C arithmetic?

For addition, check if (a > 0 && b > INT_MAX - a) or (a < 0 && b < INT_MIN - a). For multiplication, use division: if a != 0 && result / a != b, overflow occurred. Modern C provides builtins like __builtin_add_overflow that return a flag. Interviewers expect you to discuss undefined behavior for signed overflow and why explicit checks or compiler intrinsics are safer, especially in security‑critical code.

Apple

How do you safely copy overlapping memory regions?

Use memmove, which handles overlap by copying to a temporary buffer internally, ensuring correct ordering. memcpy assumes non‑overlapping regions and may corrupt data if overlap exists. Interviewers look for you to explain the underlying algorithm—copying forward or backward based on address comparison—and why memmove incurs a slight performance cost but guarantees correctness.

Amazon

Describe the steps to debug a segmentation fault.

First, reproduce the crash consistently. Run the program under gdb, use backtrace to locate the faulting instruction. Inspect pointer values, check array bounds, and verify proper allocation. Use valgrind to detect invalid reads/writes and memory leaks. Interviewers expect you to mention enabling core dumps, checking stack traces, and confirming that all pointers are initialized before use.

Netflix

How does the C preprocessor handle macro expansion with arguments?

Macros with parameters replace each occurrence of the parameter token with the argument token before compilation. The preprocessor performs textual substitution, then rescans the result for further macro expansions. Use parentheses around macro bodies to avoid precedence issues. Interviewers look for awareness of pitfalls like double evaluation, side effects, and the need for token‑pasting (##) or stringification (#) for advanced macros.

Oracle

Explain the difference between shallow and deep copy of structures.

Shallow copy duplicates the top‑level fields, copying pointers as-is, so both copies share the same referenced memory. Deep copy recursively duplicates any dynamically allocated members, producing independent copies. Interviewers look for you to illustrate with a struct containing a char* buffer: memcpy copies the pointer (shallow), while allocating new memory and copying contents yields a deep copy, preventing double free errors.

Microsoft

Advanced

Explain how you would implement a memory pool allocator.

Pre‑allocate a large block, divide it into fixed‑size chunks, and maintain a free list of available chunks. Allocation pops a chunk from the list; deallocation pushes it back. Use a bitmap or linked list for bookkeeping. Ensure thread safety with a lock or lock‑free atomic operations. Interviewers want you to discuss fragmentation reduction, constant‑time allocation, and trade‑offs like internal fragmentation versus flexibility. Mention handling alignment and possible use of mmap for large pools.

Google

What is the purpose of the restrict qualifier?

restrict tells the compiler that for the lifetime of the pointer, only it or a value derived from it will access the pointed‑to object. This enables aggressive optimizations like vectorization because the compiler can assume no aliasing. Interviewers want you to note that misuse leads to undefined behavior, and that restrict is most useful in performance‑critical code such as image processing loops.

Intel

Explain how you would implement a lock‑free stack using atomic operations.

Use a singly linked list where the head is an atomic pointer. Push performs an atomic compare‑and‑swap (CAS): read current head, set new node's next to head, then CAS head from old to new. Pop similarly reads head, sets next as new head, and CAS. If CAS fails, retry. This avoids locks, provides high concurrency, and ensures linearizability. Interviewers look for handling ABA problem, possibly with tagged pointers or hazard pointers.

Google

How would you implement a circular buffer in C?

Allocate a fixed‑size array and maintain head and tail indices modulo the buffer size. Enqueue writes at tail, increments tail; dequeue reads at head, increments head. Use a count or leave one slot empty to distinguish full vs empty. Ensure thread safety with atomic indices or mutexes. Interviewers expect you to discuss wrap‑around handling, overflow detection, and constant‑time operations.

Amazon

What are the risks of using pointer casts between unrelated types?

Casting between unrelated pointer types can violate strict aliasing rules, leading to undefined behavior. The compiler may assume objects are not aliased, enabling optimizations that break when the cast is used. It also can cause misaligned accesses and portability issues. Interviewers want you to mention using memcpy for type‑punning or the union trick, and that casts should be limited to compatible types or void*.

Qualcomm

Describe how you would detect a memory leak in a long‑running C application.

Instrument the program with a custom allocator that tracks allocations and frees, storing call stacks for each allocation. Periodically report outstanding allocations. Alternatively, use tools like Valgrind, AddressSanitizer, or LeakSanitizer in production builds. Interviewers expect you to discuss the performance impact of tracking, the importance of freeing all resources, and strategies like reference counting for complex object lifetimes.

Netflix

Common mistakes

  • Neglecting to check return values of malloc/calloc leading to null dereference.
  • Using pointer arithmetic outside array bounds, causing undefined behavior.
  • Assuming signed integer overflow is defined; it triggers undefined behavior.
  • Forgetting to free allocated memory, resulting in leaks in long‑running processes.

Study plan

  1. Review C syntax, data types, and operator precedence using a reputable textbook.
  2. Practice pointer manipulation and memory allocation exercises on online judges.
  3. Study concurrency primitives (pthreads) and implement lock‑free data structures.
  4. Run debugging sessions with gdb and memory analysis with Valgrind on sample projects.
  5. Mock interview with timed coding problems focusing on low‑level system scenarios.

FAQ

Do I need to know C++ for a C interview?

Focus on pure C concepts; most interviewers expect you to avoid C++ features. Knowing C++ can help with object‑oriented thinking, but be prepared to answer questions strictly in C.

How important is knowledge of the C11 standard?

C11 introduces atomics, thread support, and bounds‑checking functions. Many companies still use C99, but demonstrating familiarity with C11 shows up‑to‑date expertise and can give you an edge.

Should I memorize standard library functions?

Understand the purpose, typical usage, and edge cases of common functions like memcpy, strlen, and strtok. Memorizing signatures helps speed, but interviewers value reasoning about when and why to use them.

What is the best way to handle undefined behavior in answers?

Explicitly state that the construct triggers undefined behavior, explain why the standard leaves it unspecified, and propose a safe alternative. This demonstrates thorough knowledge and risk awareness.

How much time should I allocate to each interview round?

Reserve 15‑20 minutes for the phone screen, 30‑45 minutes for on‑site coding, and additional time for system design and behavioral questions. Practice pacing to ensure you can explain reasoning within these limits.

Related

Ready for your next interview?

Download MiPrep AI. Load your resume and the job description. Show up ready.

Free tier · No credit card · macOS 14+ · Windows 10+

Free tier · No credit card · Runs on your Mac or Windows machine