Debugging and Profiling # MCQs Practice set

Q.1 Which of the following is the primary goal of debugging?

Optimizing code performance
Identifying and fixing errors
Writing new features
Documenting the project
Explanation - Debugging focuses on finding and fixing errors in the code to ensure correct program behavior.
Correct answer is: Identifying and fixing errors

Q.2 What is a breakpoint in debugging?

A point where the program stops executing automatically
A line of code that cannot run
A tool for measuring memory usage
A type of runtime error
Explanation - Breakpoints are used to pause execution at a specific line of code to inspect variables and flow.
Correct answer is: A point where the program stops executing automatically

Q.3 Which debugging technique involves manually following code execution in your head?

Profiling
Code walkthrough
Breakpoint debugging
Unit testing
Explanation - Code walkthrough is the process of reading through code to mentally trace execution and find issues.
Correct answer is: Code walkthrough

Q.4 Which tool in Python is commonly used for interactive debugging?

pip
pytest
pdb
venv
Explanation - Python Debugger (pdb) is a built-in module used to set breakpoints and step through execution.
Correct answer is: pdb

Q.5 What does profiling in programming typically measure?

Code correctness
Execution time and resource usage
Compilation speed
Number of bugs
Explanation - Profiling measures performance aspects like CPU usage, memory consumption, and execution time.
Correct answer is: Execution time and resource usage

Q.6 Which of these errors is usually caught at runtime?

Syntax error
Logic error
Compilation error
Indentation error
Explanation - Logic errors do not prevent compilation but cause incorrect results during runtime.
Correct answer is: Logic error

Q.7 Which command continues program execution until the next breakpoint in most debuggers?

next
run
continue
step
Explanation - The 'continue' command resumes program execution until the next breakpoint is encountered.
Correct answer is: continue

Q.8 Which type of error does a profiler NOT detect?

Performance bottlenecks
Memory leaks
Incorrect logic
CPU usage hotspots
Explanation - Profilers analyze performance, not correctness of logic.
Correct answer is: Incorrect logic

Q.9 What is the main difference between debugging and profiling?

Debugging fixes logic, profiling measures performance
Debugging measures speed, profiling finds bugs
Both are identical
Debugging and profiling both optimize memory only
Explanation - Debugging is focused on correctness, while profiling focuses on performance optimization.
Correct answer is: Debugging fixes logic, profiling measures performance

Q.10 Which profiler is built into Python?

valgrind
gprof
cProfile
perf
Explanation - cProfile is the standard Python profiler for measuring performance statistics.
Correct answer is: cProfile

Q.11 In debugging, 'step into' means:

Execute the next line without entering functions
Execute the program until termination
Go inside a function call line by line
Skip the current line
Explanation - 'Step into' allows the debugger to move inside a function to trace its execution in detail.
Correct answer is: Go inside a function call line by line

Q.12 What does a memory profiler typically track?

Execution order
Memory allocation and leaks
File access frequency
Function call count
Explanation - Memory profilers identify which parts of the code consume memory and track leaks.
Correct answer is: Memory allocation and leaks

Q.13 Which of these errors is most difficult to detect?

Syntax error
Compilation error
Logic error
Runtime crash
Explanation - Logic errors don’t produce immediate errors but cause incorrect program behavior.
Correct answer is: Logic error

Q.14 Which debugging method involves adding print statements to code?

Breakpoint debugging
Profiling
Print debugging
Tracing
Explanation - Print debugging involves inserting print statements to inspect variable values and flow.
Correct answer is: Print debugging

Q.15 Which Linux tool is commonly used to analyze performance bottlenecks?

grep
top
perf
sed
Explanation - 'perf' is a powerful performance profiling tool in Linux systems.
Correct answer is: perf

Q.16 In profiling, 'hotspot' refers to:

A line of code with errors
A function consuming high CPU time
Unused memory
A crash log
Explanation - Hotspots are functions or parts of code that consume significant execution resources.
Correct answer is: A function consuming high CPU time

Q.17 Which debugging tool is integrated into modern IDEs?

Compiler
Debugger with breakpoints and watches
Disassembler
Linker
Explanation - IDEs provide debuggers that allow setting breakpoints, stepping, and inspecting variables.
Correct answer is: Debugger with breakpoints and watches

Q.18 Which technique helps detect memory leaks in C/C++?

gdb
valgrind
pdb
cProfile
Explanation - Valgrind is widely used for memory debugging, leak detection, and profiling.
Correct answer is: valgrind

Q.19 Which command in gdb runs the program from the start?

next
run
step
break
Explanation - The 'run' command starts the program execution inside gdb.
Correct answer is: run

Q.20 Profiling is mainly used for:

Fixing logic errors
Analyzing performance bottlenecks
Compiling code faster
Improving syntax
Explanation - Profiling helps developers identify where the program consumes the most resources.
Correct answer is: Analyzing performance bottlenecks

Q.21 Which debugging method involves reproducing the bug consistently?

Code review
Bug reproduction
Profiling
Tracing
Explanation - Reproducing a bug consistently is a key step in debugging to understand its cause.
Correct answer is: Bug reproduction

Q.22 Which language feature often makes debugging harder?

Static typing
Dynamic typing
Compilation
Indentation
Explanation - Dynamic typing may hide type-related bugs until runtime, complicating debugging.
Correct answer is: Dynamic typing

Q.23 What does the 'step over' command do in debugging?

Skips execution of the current function
Executes the next line without entering functions
Terminates the program
Continues execution until the next breakpoint
Explanation - 'Step over' runs the next line of code but skips stepping inside function calls.
Correct answer is: Executes the next line without entering functions

Q.24 Which of the following is NOT a debugging technique?

Binary search debugging
Print debugging
Breakpoint debugging
Compiler optimization
Explanation - Compiler optimization improves performance but is not a debugging method.
Correct answer is: Compiler optimization

Q.25 What does CPU profiling measure?

Memory leaks
Execution correctness
Time spent in functions
Variable values
Explanation - CPU profiling helps measure how much CPU time different functions consume.
Correct answer is: Time spent in functions