A declaration introduces a name and its type but allocates nothing, int foo(int); or extern int counter;. It tells the compiler "this exists somewhere, here's how to use it." A definition actually creates the entity: the function body int foo(int x) { ... }, or int counter = 0; which reserves storage. The compiler only needs declarations to generate calling code, it trusts the promise. The linker is what insists a definition exists, which is why a missing definition shows up as a link-time "undefined reference," not a compile error. You can declare a symbol many times but must define it exactly once (the One Definition Rule).
C Programming · Interview question
What's the difference between a declaration and a definition?
A strong answer
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
Walk me through what happens when you compile a C program.You get "undefined reference to uart_init". What stage failed and what are the likely causes?Why does changing one header file trigger a rebuild of many source files?On an embedded target, what extra build steps exist beyond a desktop compile, and why?
Browse all 472 interview questions