Microsoft KB Archive/198953

= How to expand an array pointer in the Visual C++ Debugger Watch window =

Article ID: 198953

Article Last Modified on 6/2/2005

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q198953



SUMMARY
Starting with Visual C++ version 6.0, it is now possible to expand an array pointer to view all array elements in the Visual C++ Debugger Watch window. This feature is not documented.

In the Watch window, type an expression that evaluates to a pointer followed by a comma and the number of elements in the array.



MORE INFORMATION
  Build the debug version of the following code as a console application. // Filename main.cpp // No compile option needed

#include 

void main(void) {    int * p;     char* ptr = "Hello World"; p = new int [10];

for(int i=0; i<=9; i++){*(p+i) = i+1;} cout << i < Step into the code with the debugger and stop at the last line of code. In the Watch or Quickwatch window, add the variable p or ptr. You will see a '+' symbol next to the variable. Click the '+' symbol to expand the variable. You will see only the first element of the array to which it points. Now, type p,10 or ptr,11 in the Watch window. Click the '+' symbol to expand the variable. Now you see all elements of the array to which it points.</li></ol>

If you want to see a specific range of elements, then enter the address of the first element to specify the starting index, followed by the format specifier as described in the preceding steps. For example, (p+3),8 shows elements p[3..10], and (ptr+3),10 shows elements ptr[3..12]. Unfortunately, the starting index in the Watch window will be [0], which actually corresponds to index 3 in this example. You have to remember that the offset 3 has to be added to each displayed index to get the actual index of the array element.

Additional query words: kbDSupport

Keywords: kbhowto kbinfo kbide kbdebug KB198953

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.