Programming Fundamentals · Interview question

What's the difference between a compile-time error, a runtime error, and a logic error?

A strong answer

A compile-time error is something the compiler catches before producing an executable, missing semicolons, type mismatches, undeclared variables. No binary is produced, so the program can't be run at all. A runtime error happens after a successful compile, when the program is actually executing, null pointer dereference, divide by zero, array out-of-bounds, stack overflow. The compiler couldn't predict it because it depended on values not known until runtime. A logic error is the hardest kind: the program compiles, runs without crashing, and produces output, but the output is wrong. Off-by-one in a loop, the wrong operator, a misplaced condition. Compile-time errors get caught by the compiler, runtime errors get caught by sanitizers or by crashing, but logic errors require testing to find, automated tests, sanity checks on output, or manual inspection of results.

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

Errors & Debugging

Errors are messages from the compiler trying to help. Learn to read them, distinguish the three kinds of bugs, and build the mindset that turns debugging from frustration into a skill.

More Errors & Debugging questions

Browse all 472 interview questions
What's the difference between a compile-time error, a runtime error, and a logic error? | EmbeddedPrep.io