Exercises
Learn how programmers identify, isolate, and correct software defects. This quiz covers syntax, runtime, and logic errors; reproducible test cases; breakpoints; debugger stepping commands; stack traces; watchpoints; assertions; exception handling; logging; regression searches; off-by-one errors; and cleanup with finally blocks. Questions combine practical scenarios with visual code and debugger examples.
Answer the questions below and check the explanation for each answer.
0/14 answered
Auto audio on: the next questions will be read aloud when you click Continue.
A closing parenthesis is missing. This violates the language's grammar, so the parser reports a syntax error before normal execution begins.
The code is syntactically valid, but the invalid division occurs while the program is running. It therefore produces a runtime error.
The denominator is length + 1, so 270 is divided by 4 instead of 3. The program runs, but its incorrect formula causes a logic error.
A small, repeatable test case removes unrelated factors and makes experiments easier to evaluate. Changing many sections at once makes it difficult to identify the actual cause.
A breakpoint temporarily pauses execution at a selected location. The programmer can then inspect variables, the call stack, and control flow without modifying the program's logic.
Step over executes the current call as one operation and pauses at the next statement in the current function. Step into would enter calculate.
The deepest displayed frame is parse_number, where the invalid integer conversion occurred. The other functions are callers that led execution to that point.
A watchpoint, also called a data breakpoint, pauses execution when a monitored variable or memory location changes. This helps identify the statement responsible.
An assertion documents and checks an internal invariant that should always be true. It helps reveal programming defects but should not replace normal validation or recovery logic.
Handlers should target failures the program understands and can address. Silently catching every exception can hide defects and leave the program in an invalid state.
Structured logs provide consistent context such as time, severity, operation, and request identifiers. They can be stored and searched to reconstruct behavior after a failure.
Testing the midpoint applies a binary-search strategy, often called regression bisection. With ordered pass/fail revisions, it reduces 128 candidates to the answer in about seven tests.
For a zero-based array of length 5, valid indices are 0 through 4. Using i < length stops the loop before it attempts to access index 5.
A finally block runs after the try and applicable exception handling, making it suitable for releasing resources such as files or locks.

Free CourseIntroduction to algorithms
30h53m
22 exercises

Free CourseBasic Programming Concepts
6h34m
14 exercises

Free CoursePython Data Structures and Algorithms: Learn Efficient Programming
27h59m
40 exercises

Free CourseLogical programming using C language
9h55m
25 exercises

Free CourseProgramming logic
6h56m
19 exercises

Free CourseLogical Programming in C
New
6h48m
19 exercises
Thousands of online courses in video, ebooks and audiobooks.
To test your knowledge during online courses
Generated directly from your cell phone's photo gallery and sent to your email
Download our app via QR Code or the links below:.
+ 10 million
students
Free and Valid
Certificate
60 thousand free
exercises
4.8/5 rating in
app stores
Free courses in
video and ebooks