Inserting breakpoints

To this point, the only way to find logical errors was to run a program, observe its behavior and output, then think about what in the program might have produced the erroneous results. That is the best way to approach debugging, but, if it does not yield insight into the problem, you can turn to the Visual Studio debugging tools.

Visual Studio, like all development systems, provides tools for interactive debugging of programs. To enter debugging mode, one inserts breakpoints into the program. The program executes normally until it reaches a statement with a breakpoint. It does not execute that statement, but suspends execution and enters debugging mode.

You set a breakpoint by clicking in the grey area to the left of a statement in the Code Window. As you see, the breakpoint is indicated by a purple circle and highlight. It may be cleared by clicking on the circle.

One can also create breakpoints that only suspend execution when specified conditions are true. For example, you might want to break a loop after the tenth iteration or only suspend execution if the program is processing information for a male or someone over a certain age.

To make such conditional breakpoints, right click on the breakpoint in the code window and set its properties.

Note that breakpoints only work if the program is compiled in debug mode () rather than release mode.


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.