Interview Q&A · C · 12 questions in this topic
Rapid-Fire Revision — C Interview Q&A
One-line answers spanning the whole bank — the final pass the night before the interview. Part of Scenarios & Rapid Fire · 202 questions in the C bank.
This rapid-fire round compresses the C bank into short answers for the final revision pass. Each card targets a decision made under interview pressure — storage duration, pointer decay, undefined behaviour, or the difference between two nearly identical library calls. Read the answer, then say the reason out loud; the “why” is what interviewers probe. For each card, also name the standard clause or implementation detail that makes the rule true. Use the topic menu to jump back to the full explanation whenever a one-liner is not enough.
Compiled or interpreted?
Answer
Compiled — to native machine code via object files and linking.
Pass-by-value or reference?
Answer
Strictly pass-by-value; simulated reference via pointers.
Array vs pointer?
Answer
Array is storage; pointer is an address. Arrays decay to pointers in most expressions.
malloc vs calloc?
Answer
malloc: uninitialized bytes. calloc: zeroed, overflow-checked count × size.
Safe realloc pattern?
Answer
Assign to a temporary; on NULL failure the original block stays valid.
strcpy vs snprintf copy?
Answer
strcpy is unbounded; snprintf(dst, size, "%s", src) always terminates and reports truncation.
Why not while (!feof(f))?
Answer
feof trips only after a failed read — loop on the read call itself instead.
What is a dangling pointer?
Answer
A pointer to storage whose lifetime ended — use is undefined behavior.
struct vs union?
Answer
Struct: members side by side. Union: members overlaid, one live at a time.
What is a data race?
Answer
Unsynchronized concurrent accesses with at least one write — undefined behavior (C11).
gets vs fgets?
Answer
gets is unfixably unsafe and removed (C11); fgets takes a size and is the replacement.
What finds memory bugs in CI?
Answer
AddressSanitizer + UBSan on every test run; valgrind for release-only repros.
Recommended resourcesAffiliate links · may earn us a commission