Visual Studio .NET 2005 Debugger Part II


In a previous lecture the Visual Studio .NET debugger was introduced. In this lecture the debugger will be viewed as a program passes through a for( ) loop. Open fibonacci.cpp and load it into the compiler. The code listed below is the program. Click on the bar to the left of each of the lines that are preceded by a red dot. As in the previous example of debugging, these clicks establish a stop point at each of these lines.

image from book

Run the program using Debug/Start. When this is run, you will notice in the Autos section after the first stop, values like the following:

image from book

Notice that each variable contains garbage because they have only been defined and not initialized at this point. You will recall that to continue the debugger you press F5. When you do, you should see the following where the variable first now has a value and the other variables still contain garbage similar to the following.

image from book

Press F5 one more time. This takes the program to the start of the for( ) loop. You should now see the following in Autos where index is still garbage but second has the value 1:

image from book

Press F5 one more time. You should now see the following in Autos where the variables: first, index and second have values but since third has not yet been initialized, it still contains garbage.

image from book

When you press F5 the next time, it takes you to the end of the for( ) loop prior to looping back to the loop header. Now third has a value.

image from book

Continue pressing F5 until the last of the loop where index is 10. As the program goes through each of the loops, observe how the values of each of the variables are changing. When you do this, you should see something like the following in Autos:

image from book

Now for the last stop, click F5 twice and you will see the following in Autos:

image from book

This lecture demonstrates how the Visual Studio .NET debugger may be used to view the changing values of the variables in a program. By doing this, the programmer may determine whether the program is functioning correctly by seeing the values of the variables at critical placing in a program like inside of a for( ) loop. The same process could be used with any loop and not just the for( ) loop.

Try the above demonstration again, but this time press Debug/Step Over or F10. When you use this option, the debugger stops at each line of code and not just the lines that have the stop buttons. This approach gives you even more opportunity to view the changing values of the variables during the program.




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net