1. Home
  2. Computing & Technology
  3. C / C++ / C#

How to Compile Programs with Microsoft Visual C++ 6

By , About.com Guide

6 of 8

How to Debug Your Visual C++ Applications

Debugging with Visual C++ 6
Visual C++ has a powerful debugger that's very easy to use. Let's step through our example program. To make it more interesting we'll add an int variable and watch it in a for loop.

Before the line 'std::cout', add the following two lines of code.

for (int i=0;i < 5; i++)
std::cout << "i = " << i << "\n\n";
Select the first line (for int i...) and press F9. This puts a breakpoint there- a red circle in the margin. Now press F5 to start the debugging. You can exit the debugger at any time by pressing Shift + F5.

Without the breakpoint, the program would immediately run to completion and stop. Alternatively you can start a program by pressing either F10 or F11.

You should see the three windows numbered 1-3, in the picture above. 1 Shows local variables, 2 shows the calling stack (for functions) and 3 shows variables you decide to watch. If you can't see these windows, Click "View" on the Menu then "Debug Windows" and then "Watch", "Calling Stack" or "variables" on the sub-menu.

When the program breaks at the for (int i =0;... line, the variables windows shows that i has a nonsense value, like -858993460. This has just picked up whatever was in RAM at the address of i. As soon as the loop starts executing, i takes the value 0. Press F10 to step through execution line by line.

On the next page : Learn more about stepping through code.

Explore C / C++ / C#
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C
  5. C Tutorials
  6. How to Debug Your Visual C++ Applications

©2009 About.com, a part of The New York Times Company.

All rights reserved.