C Coding Interview Checklist: Pointers, Memory, and Strings
C interviews are common for embedded, firmware, operating systems, networking, and performance-critical roles. They also feel different from interviews in higher-level languages: there's no built-in hash map, no dynamic array, and every allocation is your responsibility. Interviewers often care as much about how you handle memory as whether the algorithm is correct.
This C coding interview checklist walks through what to review and what to say out loud. Use it in the week before your round and again the night before.
Before the round
- [ ] Confirm the environment: compiled and runnable, or a plain editor?
- [ ] Confirm the standard: C99 or later is typical; it allows
//comments,boolviastdbool.h, and declaring loop variables insidefor. - [ ] Ask whether you can assume helper functions exist (like a hash map) or must write them.
- [ ] Practice in a plain editor without autocomplete or a debugger.
Pointers
Pointer questions show up directly ("reverse a linked list in place") and indirectly in nearly every problem.
- [ ] Explain the difference between
int *p(pointer to int) andint **pp(pointer to pointer), and when you need a double pointer, such as modifying a list head from inside a function. - [ ] Know pointer arithmetic:
p + 1advances bysizeof(*p)bytes. - [ ] Always check for
NULLbefore dereferencing, and say so. - [ ] Understand that arrays decay to pointers when passed to functions, so you must pass the length separately.
A good habit: when you write a function that takes a pointer, state the contract. "This function expects a non-null array of length n and does not take ownership."
Memory management
This is where C interviews are won or lost.
- [ ]
mallocreturns uninitialized memory;calloczeroes it. Pick deliberately. - [ ] Check the return value of
mallocforNULL, at least verbally. - [ ] Every
mallocneeds a matchingfree. Say who owns each allocation. - [ ] Never return a pointer to a local (stack) variable.
- [ ] Set pointers to
NULLafter freeing if they might be reused. - [ ] Know the common bugs by name: memory leak, double free, use-after-free, buffer overflow.
When you finish a solution, do a quick "ownership pass": walk through each allocation and point to where it's freed. Interviewers notice this.
Strings
C strings are arrays of char ending in '\0'. Many bugs come from forgetting that terminator.
- [ ] Allocate
strlen(s) + 1bytes when copying a string. - [ ] Know
strlen,strcmp,strncpy,memcpy,memset, and their pitfalls (for example,strncpymay not null-terminate). - [ ] For in-place problems (reverse a string, remove characters), use two indices and write the terminator at the end.
- [ ] Character arithmetic:
c - 'a'gives a 0–25 index for lowercase letters;c - '0'converts a digit. - [ ] String literals are read-only; don't modify them in place.
Arrays and building blocks
Since C has no standard dynamic array or hash map, be ready to:
- [ ] Use a fixed-size array when the problem bounds allow it (for example,
int counts[26]orint seen[256]). - [ ] Write a simple growable array with
realloc, doubling capacity. - [ ] Use
qsortwith a correct comparator:
int cmp(const void *a, const void *b) {
int x = *(const int *)a, y = *(const int *)b;
return (x > y) - (x < y);
}
Avoid return x - y; as a comparator; it can overflow for large values. Mentioning that unprompted is a nice signal.
- [ ] Know when a hash table is worth writing. If keys are small integers or characters, a direct-index array is simpler and faster.
Structs and linked structures
- [ ] Define nodes cleanly:
typedef struct Node { int val; struct Node *next; } Node; - [ ] Allocate nodes with a small helper that initializes every field.
- [ ] Use a dummy head node to simplify insertions and deletions.
- [ ] For trees, write recursive traversal and be ready to discuss stack depth.
Integers and bit operations
C questions frequently touch on low-level arithmetic.
- [ ] Signed overflow is undefined behavior; unsigned overflow wraps. Use wider types like
long longoruint64_t(fromstdint.h) when values can grow. - [ ] Integer division truncates toward zero.
- [ ] Bit tricks:
x & (x - 1)clears the lowest set bit;x & 1checks parity; shifts multiply or divide by powers of two for unsigned values. - [ ] Use unsigned types for bit manipulation to avoid surprises with sign bits.
- [ ] Use
sizeofrather than hard-coding sizes.
Explaining your code
Narrate the things a reviewer would look for:
- "I'm allocating n + 1 bytes for the terminator."
- "The caller owns this buffer and must free it."
- "This loop runs n times, so it's O(n) time and O(1) extra space."
- "I'm checking for NULL here because the list might be empty."
Then dry run with a small example, tracing pointer values step by step. With pointers, drawing boxes and arrows in comments or on a whiteboard is often the fastest way to catch bugs.
Common mistakes
- Off-by-one errors on loops and buffer sizes
- Forgetting the null terminator
- Returning addresses of local variables
- Modifying a pointer copy and expecting the caller's pointer to change
- Leaking memory on early-return paths
Practice under real conditions
C rewards careful, deliberate practice: plain editor, timer running, explaining every allocation out loud. Luna Interview gives you a structured way to rehearse that loop and stay calm when a pointer bug shows up mid-round.
Night-before checklist
- [ ] Linked list reverse and merge written from scratch
- [ ] Growable array with
reallocwritten once - [ ]
qsortcomparator memorized (overflow-safe) - [ ] String copy with correct terminator
- [ ] Ownership pass habit practiced
- [ ] Bit tricks refreshed
C interviews reward precision. Slow down, state your assumptions, and treat memory as part of the answer.
Rehearse with an AI interview copilot, then browse commonly reported interview questions.