How to expand Visual C + + array pointers in the Debugger watch Window
Profile
from Visual C + + 6.0 the beginning of the version can now expand the array to point to the Visual C + + View all array elements in the Debugger watch window. This feature is not logged. In the Watch window, type ...
Starting with Visual C + + version 6.0, you can now expand the array to point to view all array elements in the Visual C + + Debugger Watch window. This feature is not logged.
In the Watch window, type an expression that evaluates to a pointer followed by the number of elements in a comma and array.
More information
generate a debug version of the following code as a console application. //Filenamemain.cpp//No compile option needed #include ...
- Generate a debug version of the following code as a console application.
- 2.//filename main.cpp
- 3.//no compile option needed
- 4.
- 5. #include <iostream.h>
- 6.
- 7. void Main (void)
- 8. {
- 9. int * p;
- char* ptr = "Hello world";
- p = new int [10];
- for (int i=0; i<=9; i++) {* (p+i) = i+1;}
- cout << i <<endl;
- }
- Enter and step through the code using the debugger and stop at the last line of code.
- Add the variable pptr in the Watch or QuickWatch window. You'll see A + sign next to the variable.
- Click the + symbol to expand the variable. You will see the first element of the array it points to.
- Now, in theWatch window, type p,ten or ptr,one by one.
- Click the + symbol to expand the variable. Now, you see that it points to all the elements of the array.
If you want to view a specific range of elements, then enter the first element to specify the address of the starting index appended with the format specifier, as described in the previous steps. For example (p+3),8 shows elements p [3..10] and (ptr+3), and the element ptr [3..12] is displayed. Unfortunately, the index starting in the Watch window will actually correspond to index 3 in this example for [0]. You must remember that an offset of 3 has to be added to each displayed index to get the actual index of the array element.
How to expand the array pointer in the Visual C + + Debugger Watch Window