Programming and Software Development: Question 2
Syllabus 12.3
A programmer writes this line of pseudocode, intending to declare an integer variable to store a customer's account number, but the colon before the data type has accidentally been left out.
DECLARE AccountNumber INTEGER
When this program is translated, before it is even run, what type of error will this line cause?
Show worked solution Hide worked solution
Worked solution
Why option A is correct
Pseudocode declarations must follow an exact grammar: DECLARE <name> : <type>, with a colon
separating the variable’s name from its data type. The line shown, DECLARE AccountNumber INTEGER,
is missing this colon, so it does not match the required structure of a DECLARE statement.
A translator (an interpreter or compiler) checks that every line of code obeys the grammar rules
of the language before it can be converted into a form the computer can execute. A line that
breaks these grammar rules, like a DECLARE statement missing its colon, causes a syntax
error. It is detected during translation, before the program is ever run.
Why the other options are wrong
- B (logic error): a logic error happens when a program runs successfully and produces output, but that output is wrong because of a mistake in the reasoning or algorithm (for example, using the wrong formula). This line cannot even be translated, so it cannot produce “the wrong value when the program runs”. The program never gets that far.
- C (runtime error): a runtime error happens while a successfully translated program is executing. For example, dividing by zero or accessing an array index that does not exist. This line fails during translation, before execution can even begin, so no runtime error can occur here.
- D (no error): a translator strictly checks a program against the language’s exact grammar rules; it cannot guess an intended meaning for a line that breaks those rules, so the missing colon does cause an error.
Final answer
- A. A
DECLAREstatement missing the required colon between the variable name and its data type breaks the grammar rules of the pseudocode language, causing a syntax error, detected before the program is ever run.