Before the line 'std::cout', add the following two lines of code.
for (int i=0;i < 5; i++)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.
std::cout << "i = " << i << "\n\n";
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.


