Interview Q&A · C · 6 questions in this topic
C Standards & Tooling — C Interview Q&A
How the language evolved — C89 to C23, what each revision changed, and the compiler flags that matter. Part of C Fundamentals · 202 questions in the C bank.
What are the C standards (C89, C99, C11, C17, C23) and what did each change?
Answer
C89/C90 is the ANSI baseline every compiler supports. C99 added // comments, mixed declarations, stdint.h, stdbool.h, variable-length arrays and snprintf. C11 added _Static_assert, _Generic, threads (<threads.h>), atomics (<stdatomic.h>) and anonymous structs/unions. C17 fixed defects only. C23 adds constexpr, typeof, auto type inference, bit-precise _BitInt, #embed and decimal floating types.
Compile with -std=c17 (or c11) plus -Wall -Wextra -pedantic so the standard you claim is the standard you get.
Key points
- 1C89 — the portable baseline.
- 2C99 — stdint/stdbool, declarations anywhere, snprintf, VLAs.
- 3C11 — static assert, generics, threads, atomics.
- 4C17 — defect fixes; C23 — constexpr, typeof, auto, #embed.
Example
/* gcc -std=c17 -Wall -Wextra -pedantic main.c -o app */ #include <stdint.h> /* C99: exact-width integers */ _Static_assert(sizeof(int) >= 2, "int too small"); /* C11 */
💡 Pair each standard with one flagship feature — interviewers remember the mapping, not the year list.
What compiler warnings and flags should every C build use?
Answer
At minimum -Wall -Wextra -Werror with an explicit -std (c11/c17), plus -g for debug symbols and -O2 for realistic optimization. Add -Wpedantic, -Wconversion and -fanalyzer for stricter checking, and sanitizers (-fsanitize=address,undefined) in test builds.
Warnings are cheapest bug detection available — a clean -Wall -Wextra build is the entry ticket before any review.
Example
/* gcc -std=c17 -Wall -Wextra -Werror -g -O2 main.c -o app */ /* gcc -std=c17 -fsanitize=address,undefined -g main.c -o app_dbg */
💡 Saying -Werror shows you treat warnings as bugs, which is exactly the team habit interviewers want.
What is the difference between compiler, linker and loader errors?
Answer
Compiler errors are per translation unit: syntax, types, undeclared names — with file/line diagnostics. Linker errors are cross-unit: undefined reference (declared, never defined/linked), multiple definition, missing library paths. Loader errors happen at startup: missing shared libraries, ABI mismatches, bad rpaths.
Read the phase first: the phase tells you where to look (code vs build graph vs deployment).
Key points
- 1Compiler — inside one TU: types and syntax.
- 2Linker — across TUs: symbols and libraries.
- 3Loader — at startup: shared objects and paths.
Example
/* undefined reference to `read_sensor' -> linker: sensor.c missing */ /* error: no matching function -> compiler: type bug */
💡 Naming the phase before debugging saves most build-investigation time.
What does `sizeof` do, and is it a function?
Answer
sizeof is a compile-time operator (not a function — no parentheses needed for expressions) giving the byte size of a type or object, including padding. sizeof(char) is always 1; everything else is implementation-defined. Prefer sizeof(array)/sizeof(array[0]) for element counts and sizeof(*p) over repeating the type in malloc.
Because it is compile-time, sizeof never evaluates its operand (except VLAs) — sizeof(i++) changes nothing.
Example
#include <stdio.h> int a[10]; size_t n = sizeof a / sizeof a[0]; /* 10, no magic number */ int *p = malloc(100 * sizeof *p); /* type follows the pointer */
What is the difference between static and dynamic linking?
Answer
Static linking copies library code into the executable: single file, no runtime dependency, larger binary, updates require relinking. Dynamic linking references shared libraries loaded at startup: smaller binaries, shared memory, independent updates — at the cost of load time, versioning pain and deployment complexity.
Static suits self-contained tools and embedded targets; dynamic suits system libraries and plugin ecosystems.
Key points
- 1Static (.a) — baked in at link time.
- 2Dynamic (.so/.dll) — resolved at load/run time.
- 3Trade-off — size and hermeticity vs sharing and updatability.
How do you debug a C program that segfaults once a day in production?
Answer
Reproduce under sanitizers first (ASan/UBSan usually catch it in minutes), enable core dumps built with symbols, and bisect recent changes. Read the crashing stack for use-after-free, buffer overflow, data races (then TSan) and double-free. Fix the ownership/bounds root cause, add a regression test, and put sanitizers into CI.
Narrate hypothesis-first: read the stack, form one theory, prove it with a sanitizer — not printf roulette.
Key points
- 1Capture — core dump, logs, exact build symbols.
- 2Reproduce — sanitizers (ASan/UBSan/TSan) over guessing.
- 3Fix root cause, regress-test, harden CI.
💡 Say sanitizers before logs — that ordering signals production experience.
Recommended resourcesAffiliate links · may earn us a commission