Skip to content
IGCSE·Tuition
Computer Science · Lesson

Compare interpreter and compiler behaviour

You can recall that both translate code, but an exam question about errors or speed makes the two blur together.

On this page
  1. Why do programs need translating?
  2. How do the two behave?
  3. Worked example
  4. The mistake to watch for
  5. Check yourself
  6. Where this leads next

A compiler translates the whole program from a high-level language into machine code in one go, before the program runs. An interpreter translates and runs the program one statement at a time. Exam questions ask you to compare the two, often through error reporting, speed or distribution.

This lesson follows operating system and application roles in the software and systems module.

Why do programs need translating?

The processor only understands machine code, which is binary instructions. People write in high-level languages such as Python or pseudocode-like languages because they are readable. A translator closes that gap.

The program you write is the source code. What the compiler produces is the object code, or executable. An interpreter produces no separate file.

How do the two behave?

FeatureCompilerInterpreter
TranslationWhole program at onceOne statement at a time, while running
OutputA separate executable fileNo file produced
ErrorsLists errors after attempting the whole program; nothing runs until they are fixedStops at the first error; earlier lines have already run
Running againRuns the executable directly, no translator neededTranslates again every time
Speed of runningFasterSlower
SharingThe user gets the executable and not the source codeThe user needs the interpreter and the source

Worked example

A short program has an error on line 4, because totl was typed instead of total.

1  total ← 0
2  OUTPUT "Start"
3  total ← total + 5
4  OUTPUT totl
5  OUTPUT "Done"

Interpreter, traced:

StepLineWhat happensScreen output
11total is set to 0none
22Prints StartStart
33total becomes 5none
44totl is not defined: error reported, run stopserror message
55Never reachednone

The user sees “Start” and then an error message pointing at line 4.

Compiler: the compiler reads all five lines first, finds the undefined totl on line 4, and reports it. No executable is produced, so nothing runs at all and “Start” is never displayed. After you fix line 4 and compile again, the executable runs and displays Start, then 5, then Done.

The mistake to watch for

Mistaken answer: “A compiler translates the program line by line and stops when it finds an error.”

That describes an interpreter. The compiler works on the whole program and normally reports its errors together, so you can fix several at once. Check your answer with one question: did the code run while it was being translated? If yes, it is an interpreter.

A second slip is saying “the interpreter is faster because it runs straight away”. It starts sooner, but each run is slower, because the translation is repeated.

Check yourself

1. A company wants to sell its game without letting buyers see the source code. Which translator suits, and why?

Show answer

A compiler. It produces an executable file made of machine code, so the company can distribute that file and keep the source code private.

2. A student is learning to program and wants to test one line at a time as it is written. Which translator suits, and why?

Show answer

An interpreter. It runs each statement straight away and stops at the first error, so the student sees at once which line is faulty.

3. Using the program above with the typo fixed (OUTPUT total), what is displayed?

Show answer

Line 2 prints Start. Line 3 makes total equal to 0 + 5 = 5. Line 4 prints 5. Line 5 prints Done. Output: Start, 5, Done.

Where this leads next

Next, see how the processor reacts to events while programs run, in explain an interrupt using a scenario. If you want to watch a loop trace step by step, try the restricted pseudocode trace trainer.

Comparison questions reward exact contrast words such as “whole program” and “one statement at a time”. A teacher in online one-to-one Computer Science tuition can help you tighten those phrases.

Questions people ask

Does a compiler run the program?

No. A compiler translates the whole source code into machine code and produces a separate executable file. The program is run afterwards, and the compiler does not need to be present. An interpreter does both jobs together, translating and running one statement at a time.

Why is an interpreter useful while writing a program?

An interpreter runs the code straight away and stops at the first error, so the programmer sees the faulty line quickly and can fix it. There is no waiting for a full translation. This suits testing and learning, though the program runs more slowly each time.

Which one gives faster execution?

Compiled code usually runs faster, because translation has already been done and the processor executes machine code directly. Interpreted code is translated again every time it runs. Say this as a comparison of running speed, not of how fast you can start testing.

Updated:

Your next step

If compiler and interpreter answers still sound the same on paper, a one-to-one teacher can have you explain each in a new scenario until the contrast is automatic.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parents: enquire here

  • 9,000+ students helped through our service
  • 9+ years helping IGCSE students