Hi. I am new to C and I am using MS Visual C++ 6.0 for now. I am currently working on sorting algorithms and i want to track the values of each variable automatically. This may provide me insight on how the algorithm does the hard work. That is, I don't want to write what is produced by what on a paper :) Are there are any operators or functions for debugging purposes such as var_dump() in PHP? or How can I improve my debugging abilities? Any other debugging tools for newbies? or any good tutorials on using Visual C++'s built-in debugger? Thank you!..
In Visual C++, you can set breakpoints on the lines of code that you wrote using the F9 key. You will see a little red dot to the left of that line. Then hit F5 to compile and run.
f10 steps line by line. I think F11 steps into a method.
You can also do trace outputs and debug strings to the output window if you want.
When you set the breakpoints, you can watch variables in a window - and I think the ones on the stack will automatically be in the stack/auto variable window. I am sorry I don't have VC6 in front of me right now to give more details or screenshots.
printf
/fprintf
is the most easy to use debugging tool. It is much easier to analyze what happens if your program logs its activities. I prefer logging to visual debuggers, because it is less interactive and allows to analyze what happened after the program run.
PS. It is better not to pollute stdout, and direct your debug output to file or to stderr.
I think what you're looking for are called "Watches" in Visual Studio. You can add expressions (such as variable names) as items to watch, and as you step through the code their values are automagically updated. You may also be interested in the "Locals" debugging window, which is like Watches except that it is populated with whatever variables are local to the current scope.
Here is a quick tutorial on using Locals and Watches that I found via Google. Also check out this other SO question about best debugging methods.
Use (ALT)(F4) to bring up the variables window This will show the variables for the current statment.
Use (ALT)(F3) to bring up the watch window. You can add variables there, so watch them while they are in scope.
Look under View debug windows, for other options.