10. Arrays

Arrays in Debugger

Let us now run the previous program with a debugger. Start the debugger by pressing F10 (Step Into) and repeat pressing F10 to execute the program statement by statement. Whenever the statement that reads data from standard input executes, the console will pop out to allow you to type in input data.

When you have completed entering the data and the first for loop completes, pay attention to the variable inputValues in the Locals window. There is a small arrow next to the name of the variable. The variable inputValues has 5 elements. To see all the elements, click on the small arrow.

In some older debuggers, you might notice two variables named i, which is due to slight imperfections of older debuggers. As we have already said, a loop variable gets removed after the for loop completes.

You can continue pressing F10 to observe how the minimum value algorithm works. The values of variables can be followed in the Locals window, as usual.

When the final for loop completes its execution, you can stop the debugger.

As we have already said, a loop variable gets removed after the for loop completes. Let us now prove that the variable i does get removed after a for loop completes. Add the following statement after the first for loop:

    cout << i << endl;

Try to run the program, or just build it by using BUILD -> Build Solution from the menu. The compiler will produce the following error:

'i': undeclared identifier

"Identifier" is a name, and "undeclared" means that it has not been introduced. So, the compiler is stating that a variable i which does not exist at this place in the code is being used.