Identifying and Correcting Errors (College Board AP® Computer Science Principles): Exam Questions

11 mins11 questions
1
1 point

A program runs to completion with no error messages, but the total it prints is always lower than it should be. What type of error is this most likely to be?

  • Syntax error

  • Logic error

  • Runtime error

  • Overflow error

2
1 point

Which statement is true of a syntax error?

  • It produces a wrong answer but lets the program run

  • It only appears while the program is running

  • It is detected before the program runs and prevents it from executing

  • It never affects whether the program runs

3
1 point

A program asks the user to type a number and then uses it in a calculation. It works normally until a user types letters instead, at which point the program stops unexpectedly partway through. What type of error is this?

  • Overflow error

  • Syntax error

  • Logic error

  • Runtime error

4
1 point

Which statement about overflow errors is correct?

  • An overflow error occurs when a computer attempts to handle a number that is outside of the defined range of values

  • An overflow error is a type of syntax error caught before the program runs

  • An overflow error happens when the code is missing a bracket

  • An overflow error occurs only in programs that have no comments

5
1 point

A developer suspects a logic error inside a loop, so they step through the code on paper, writing down the value of each variable at every line. Which error-detection method is this?

  • Using a debugger

  • Hand tracing

  • Setting a breakpoint

  • Code attribution

6
1 point

A program passes every test that uses typical values, but after release some users still hit errors. What is the most likely reason?

  • It was developed using an iterative process

  • It contains too many comments

  • Its variable names are unclear

  • It was not tested with boundary and extreme inputs

7
1 point

An online store gives free shipping for orders of $25 or more. Which set of test inputs best checks the boundary where the free-shipping rule changes?

  • $24 and $25

  • $5 and $50

  • $10 and $40

  • $100 and $200

8
1 point

Consider the following code segment, which is intended to display each value in the list nums. What type of error, if any, occurs when the segment is executed?

nums ← [4, 8, 15]
i ← 1
REPEAT 4 TIMES
{
  DISPLAY(nums[i])
  i ← i + 1
}
  • Syntax error, because the loop keyword is used incorrectly

  • Logic error, because the loop repeats one too many times but the program still finishes

  • No error occurs; the segment displays 4, 8, and 15

  • Runtime error, because the code tries to access a list element that does not exist

9
1 point

A program reads a whole-number temperature and displays "Freezing" for values below 0, "Liquid" for values from 0 to 100 inclusive, and "Gas" for values above 100. Which set of test inputs is the most effective for checking that every output branch works correctly?

  • -1, 0, 100, 101

  • 20, 40, 60, 80

  • 50, 500

  • 0, 50, 100

10
1 point

A developer is asked to test a program but is given only the finished code, with no description of what the program is supposed to do. Why does this make effective testing difficult?

  • Without the program's requirements there is no way to know what output each input should produce, so there is nothing to compare the results against

  • Testing can only be carried out by the person who wrote the program

  • A program cannot be run until documentation has been written for it

  • Test inputs have to be chosen in the order in which the code was written

11
1 point

A developer thinks a variable inside a loop is being updated incorrectly, but the programming environment they are using has no debugger. Which of the following would let them see how the variable changes as the loop runs?

  • Adding more comments beside the loop

  • Giving the variable a longer, more descriptive name

  • Increasing the number of times the loop repeats

  • Adding an extra statement inside the loop that displays the variable's value on each pass