Identifying and Correcting Errors MCQ Practice

Question 1 of 10

A student writes DISPLAY("Hello) and the programming environment reports a syntax error before the program runs.

What kind of error is this, and what is an appropriate first correction step?

  1. A. Syntax error; fix the mismatched quotation marks/parentheses so the statement is well formed
  2. B. Overflow error; buy more memory
  3. C. Runtime network error; restart the router
  4. D. Logic error; change the intended greeting message randomly

Question 2 of 10

This program is meant to display the sum of numbers from 1 through n inclusive:

n ← INPUT()
sum ← 0
i ← 1
REPEAT UNTIL i > n
{
    sum ← sum + i
}
DISPLAY(sum)

For n = 3 the program appears to hang. Which diagnosis is best?

  1. A. Syntax error in DISPLAY
  2. B. Logic error: i never increases, so the loop never ends
  3. C. The sum formula is impossible for n = 3
  4. D. INPUT cannot read the number 3

Question 3 of 10

A ticket counter stores seatsLeft as an 8-bit unsigned integer (max 255). A school assembly needs 300 seats reserved in one operation: seatsLeft ← seatsLeft - 300 when seatsLeft was 40.

Which error type is most likely, and what is a mitigation?

  1. A. Logic errors cannot involve numbers
  2. B. Syntax error; rewrite subtraction as addition
  3. C. Overflow/underflow style numeric limit error; validate that 300 ≤ seatsLeft before subtracting or use a wider representation
  4. D. The reservation succeeded with seatsLeft = 40 still

Question 4 of 10

A list of lab stations is 1-based with length 4. Code should light the last station:

stations ← ["A", "B", "C", "D"]
index ← LENGTH(stations) + 1
DISPLAY(stations[index])

What goes wrong, and how should it be corrected?

  1. A. LENGTH always returns 0
  2. B. DISPLAY cannot show list elements
  3. C. Nothing; index 5 is valid for length 4
  4. D. Off-by-one: index becomes 5, past the last element; use LENGTH(stations) or 4

Question 5 of 10

Which testing practice is most likely to catch a wrong boundary in a password-length checker that must accept lengths 8 through 16 inclusive?

  1. A. Testing lengths 7, 8, 16, and 17 and comparing to expected accept/reject results
  2. B. Never testing rejected passwords
  3. C. Testing only the color of the login button
  4. D. Only testing length 12

Question 6 of 10

Hand-tracing means:

  1. A. Deleting code until the file is empty
  2. B. Manually stepping through statements with sample values to predict state and output
  3. C. Asking the compiler to invent requirements
  4. D. Formatting the keyboard with soap

Question 7 of 10

Intended: display every name in visitors. Actual code:

visitors ← ["Nia", "Omar", "Pia"]
i ← 1
REPEAT UNTIL i ≥ LENGTH(visitors)
{
    DISPLAY(visitors[i])
    i ← i + 1
}

What is displayed, and what error type is this?

  1. A. Nothing; overflow on i
  2. B. Nia Omar Pia; no error
  3. C. Nia Omar; logic/off-by-one because the loop stops when i reaches 3 before displaying Pia
  4. D. Only Pia; syntax error

Question 8 of 10

A runtime error occurs when a robot executes MOVE_FORWARD into a wall and the simulator halts.

Which debugging step best isolates the fault?

  1. A. Delete all ROTATE commands permanently
  2. B. Replace the robot with a syntax error
  3. C. Ignore the halt and assume the destination was reached
  4. D. Reproduce with a small grid, note the robot pose before the failing move, and check CAN_MOVE before moving

Question 9 of 10

A program runs and finishes but prints the average of a list as 0 when the list held positive numbers because the divisor used was LENGTH(list) - LENGTH(list).

This is best classified as:

  1. A. A logic error producing incorrect results without necessarily crashing
  2. B. Impossible because averages cannot be wrong
  3. C. An acknowledgment error in documentation licenses
  4. D. A syntax error caught before execution

Question 10 of 10

Students record these test results for a grade-rounder that should round 0.5 upward:

Input Expected Actual
2.1 2 2
2.5 3 2
2.6 3 3
-1.5 -1 -2

Which conclusion is best?

  1. A. All tests pass, so ship immediately
  2. B. Half-up rounding fails on 2.5 and the negative case looks wrong; investigate the rounding algorithm
  3. C. Only syntax errors can fail tables
  4. D. Inputs cannot be decimals