大网数据广告活动
Web服务器与PHP

Expand an array pointer in VC++ debugger

· 52CE 我爱测

Describes how to expand an array pointer to view all array elements in the Visual C++ Debugger Watch window.

This article describes how to expand an array pointer to view all array elements in the Visual C++ debugger Watch window.

Original product version:   Visual C++
Original KB number:   198953

Summary

Starting with Visual C++ version 6.0, it's now possible to expand an array pointer to view all array elements in the Visual C++ debugger Watch window. This feature isn't 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

  1. Build the debug version of the following code as a console application.

    // Filename main.cpp
    // No compile option needed
    #include <iostream.h>
    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 <<endl;
    }
    
  2. Step into the code with the debugger and stop at the last line of code.

  3. In the Watch or QuickWatch window, add the variable p or ptr . You'll see a plus (+) symbol next to the variable.

  4. Click the plus (+) symbol to expand the variable. You'll see only the first element of the array to which it points.

  5. Now, type p,10 or ptr,11 in the Watch window.

  6. Click the plus (+) symbol to expand the variable. Now you see all elements of the array to which it points.

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. Remember that the offset 3 has to be added to each displayed index to get the actual index of the array element.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 04/16/2020
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。