C Programming · Interview question

Walk me through what happens when you compile a C program.

A strong answer

Four stages. The preprocessor expands #includes, macros, and conditional-compilation directives into a single block of pure C text. The compiler parses and type-checks that text, runs optimizations, and emits assembly for the target architecture. The assembler turns the assembly into a machine-code object file (.o) containing sections like .text, .data, .bss, plus a symbol table of what it defines and what it references. Finally the linker combines all object files and libraries, resolves every external symbol reference to a definition, lays out the sections, and produces the executable. Each .c is compiled independently as a translation unit, which is why the linker exists, to connect them.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

The C Compilation Pipeline

What gcc actually does between your .c file and a flashable binary, and why 'undefined reference' and 'implicit declaration' are different bugs at different stages.

More The C Compilation Pipeline questions

Browse all 472 interview questions