In a C coding interview, say what your function expects, who owns the memory, and what happens at the boundary before you start writing. Practise with a bounded palindrome check, an in-place array edit and a linked-list reversal. Those three exercises let you demonstrate control over array lengths, object lifetimes and pointer updates while you explain the algorithm.
What should you clarify before writing C in an interview?
Ask which C standard and library calls you can use, whether you can change the input, and how the caller wants failures reported. If the prompt says “reverse this string”, ask whether it is a writable, null-terminated string or a byte buffer with an explicit length. If you get a string literal, you’ll need separate writable storage. If you get a buffer, an embedded zero may be data. That one question changes the interface, the loop and the tests you’ll write.
C is a procedural language used in systems and embedded software, where questions about representation and object lifetime can be part of a routine coding exercise. When an interviewer asks about types or syntax, connect the answer to your implementation. Use size_t for sizes reported by sizeof, avoid assuming an int has a particular width, and make sure each loop stops within the object it indexes. If the input comes from a signed numeric field, check whether it’s negative before converting it to a size. With a switch, point out where a break belongs if each case should run independently.
In a collaborative editor, say “I’ll treat length zero as valid and skip all dereferences” before you trace the loop. That gives the interviewer a specific assumption to challenge. The live coding interview practice guide has more on clarifying a task and talking through the tests as you go.
How do you check a palindrome without reading past the buffer?

Compare matching bytes from the two ends of a read-only buffer. On a whiteboard, draw five adjacent cells for the letters in “radar” and point to the outer pair first. Use that picture to explain where the indices start, when they advance and why the centre byte needs no comparison. The function below takes an explicit length, so it can handle data with embedded zero bytes. For a nonzero length the caller must provide at least that many readable bytes.
#include <stdbool.h>
#include <stddef.h>
bool is_palindrome(const unsigned char *bytes, size_t len)
{
for (size_t left = 0; left < len / 2; ++left) {
size_t right = len - 1 - left;
if (bytes[left] != bytes[right]) {
return false;
}
}
return true;
}
Trace an empty buffer and a one-byte buffer first. Neither enters the loop, so the subtraction never happens for length zero. Then try an even-length match such as abba, an even-length mismatch such as abca, and the byte sequence {1, 0, 1}. Those cases exercise an even centre, an inner mismatch and a zero in the data. The loop uses O(n) time in the worst case and O(1) auxiliary space.
If the follow-up says “ignore punctuation and case”, ask about the character set. An ASCII-only contract lets you skip a defined set of bytes and compare folded letters. If the caller expects Unicode text, agree on how to handle encoding, normalisation and case before choosing an algorithm. Reversing or comparing raw UTF-8 bytes can split a character into parts that have no meaning on their own.
How do you remove duplicates from a sorted array in place?
You’re given a writable sorted array and its element count. Return the number of distinct values at the front. The caller keeps the same allocation and uses the returned count as the new logical length.
#include <stddef.h>
size_t compact_sorted(int *values, size_t count)
{
if (count == 0) {
return 0;
}
size_t written = 1;
for (size_t read = 1; read < count; ++read) {
if (values[read] != values[written - 1]) {
values[written++] = values[read];
}
}
return written;
}
Explain the invariant as you point at the array. Everything before written is already the distinct prefix, and read points at the next unprocessed element. The write position never moves ahead of the read position. With {2, 2, 5, 5, 7}, you return three and the prefix is {2, 5, 7}. Test all-equal and all-distinct input as well. The first should return one for nonempty input. The second should retain the original order and length. The scan takes O(n) time and O(1) auxiliary space.
A useful follow-up is “What if it’s unsorted and you must preserve the first occurrence?” An in-place scan of the accepted prefix can still work, with quadratic worst-case time. A hash set can reduce expected running time at the cost of extra memory. If sorting is acceptable, you can sort and then compact, but that changes the original order. Ask which property matters to the caller before choosing one.
Which pointer and memory questions should you rehearse?
Why pass an array length separately? An array object and a pointer have different types. In a function parameter, a declaration such as int a[] is adjusted to a pointer, so sizeof a gives the size of that pointer. Calculate the count where the array object is in scope and pass it with the pointer. For pointer arithmetic, stay within the same array object or reach its one-past position. That position is useful as an end marker and must never be dereferenced. GNU C Language Manual
When would you use malloc, calloc or realloc? Use malloc to reserve a byte count and initialise the data before reading it. calloc takes an element count and element size and sets the allocated bytes to zero. For nonzero resizing, keep the result of realloc in a temporary pointer. If it returns null, the original allocation is still yours. On success, use the returned pointer and recreate any interior pointers from known offsets. For an allocation size you compute yourself, check that the element count fits before multiplying by sizeof *items. Explain what happens on failure before you change a stored pointer or capacity.
What makes a pointer dangle? The object it referred to has ended its lifetime. Freeing an allocation or returning the address of an automatic local variable can leave such a pointer behind. Setting one pointer to null after freeing does nothing to aliases. Give the interviewer a clear owner for each allocation and say how long a borrowed pointer stays usable. When chasing a leak, trace ownership from allocation through the successful return and every early exit. Exercise a failing path as well as a happy path with your environment’s available memory diagnostics.
How do you reverse a linked list without losing nodes?

Assume a finite, acyclic singly linked list you’re allowed to modify. Before changing the current node’s link, save the rest of the list. Then move the current node to the front of the reversed prefix.
#include <stddef.h>
struct node {
int value;
struct node *next;
};
struct node *reverse_list(struct node *head)
{
struct node *previous = NULL;
while (head != NULL) {
struct node *remaining = head->next;
head->next = previous;
previous = head;
head = remaining;
}
return previous;
}
Trace three nodes on paper using arrows. After the first loop, the original head points to null while head still points to the second node. Check an empty list, one node and three nodes. In that last test, walk from the returned head through all three original nodes and confirm the tail link is null. The iterative solution uses O(n) time and O(1) auxiliary space. Recursion can express the same idea, with call-stack space proportional to list length. If the nodes are shared with another caller, ask whether its view must stay intact. A separate reversed list may be needed, which makes allocation failure and ownership part of the answer.
What follow-ups test more than syntax?
What does static mean here? A local static object retains its value between calls. A file-scope declaration with static can keep a function or object name local to its translation unit through internal linkage. When the follow-up asks whether that local static counter is safe across threads, describe the shared access. Coordinate reads and writes with a lock or use atomics when the operation fits. volatile does not make an increment atomic or synchronise threads.
When would you use a function pointer, struct or union? A function pointer lets the caller supply behaviour, such as a comparison callback. Say what the callback receives and returns before you write it. For a record, a struct holds separate members, with possible padding. A union overlaps the members’ storage. A tagged union pairs that storage with an explicit tag so code can track which variant it wrote. If a follow-up asks you to store those records in a file, define the on-disk representation. Raw struct bytes can depend on padding and machine byte order.
How would you read a file safely? Decide whether the data is text or binary and open the stream in the corresponding mode. Check that fopen succeeds, handle a short read, and distinguish end-of-file from an I/O error before you close the stream. If you parse decimal text with strtol, check for a missing conversion, unwanted trailing characters and overflow before narrowing the result. If you’re asked to explain a macro while debugging, show how preprocessing can duplicate an argument expression. An inline function can give you typed parameters and ordinary function argument semantics for a simple helper.
How would you handle an arithmetic drill? For a Fibonacci exercise, name the base cases, implement a loop that retains the previous two values and say how your function handles a request beyond its numeric range. Signed overflow is undefined in C. Arithmetic in an unsigned result type wraps modulo its range, which still produces the wrong mathematical answer for this exercise. A check before addition lets you report failure without returning a misleading number. For a swap, use a temporary variable and explain that modifying the caller’s two objects requires their addresses.
How can you rehearse before the real interview?
Give yourself 35 minutes. Spend five saying the contracts and drawing the initial state, fifteen writing the compacting and list-reversal functions, ten running boundary cases and five on a follow-up. Ask a practice partner to read “the input is no longer sorted” aloud. If you’re practising alone, record yourself answering it in one take and replay the point where you decide which assumption changed.
Score the rehearsal out of four. Give yourself one point for stating the input and ownership contract, one for tracing a normal case, one for exposing a boundary or failure case, and one for adapting your choice when the requirement changes. For the next session, redo the first exercise where you lost a point. If your invitation names an editor, use the CoderPad practice questions to rehearse the shared-editor flow separately.
To practise responding to interruptions, use Hiintly during a mock session and ask a partner to stop you halfway through your explanation. Try one free 10-minute session and return to it after the five-minute cooldown. Listen for the moment you can state your current invariant in a sentence and pick up the trace from there.
Frequently Asked Questions
- What C coding interview questions should I practise first?
- Start with a bounded string or byte-buffer exercise, an in-place array edit and a linked-list operation. Say the contract aloud, then trace empty input, a one-item case and a representative longer case.
- Do I need to memorise C standard library functions for an interview?
- Learn the contracts and failure behaviour for the functions you expect to use, including allocation, string conversion and I/O. Ask at the start whether library calls or reference material are allowed.
- What should I say when I use a pointer in a C interview?
- Describe the object it refers to, how long that object remains valid and who owns it. If you’re indexing a buffer, explain where its length comes from and what counts as a valid index.
- What if there’s no compiler in my C interview?
- Trace a short input on paper or a whiteboard. Write down index values and pointer changes after each step, then check an empty input or a failure path under the same contract.
- Is it worth practising C if the interview lets me choose another language?
- Use C when the role calls for C or when you can solve and test the task confidently in it. If the interviewer accepts another familiar language and assesses general algorithms, weigh the extra time C can require for memory and input handling.

aa.png)


