Is it possible to view an array in the Visual Studio debugger? QuickWatch only shows the first element of the array.
-
4http://support.microsoft.com/kb/198953 – a06e Aug 22 '12 at 19:35
-
If it is a CArray, writing array.m_pData[pos] or array->m_pData[pos] (depending on the case) on the Watch Window lets you see the contents of array at the pos position! – sergiol Jul 15 '14 at 01:13
5 Answers
You can try this nice little trick for C++. Take the expression which gives you the array and then append a comma and the number of elements you want to see. Expanding that value will show you elements 0-(N-1) where N is the number you add after the comma.
For example if pArray
is the array, type pArray,10
in the watch window.
-
18Incredible find. It does however only work with immediate values, no arithmetic or dynamic member access is allowed. – Sebastian Graf Oct 29 '12 at 15:40
-
35Note that you can also use a cast in the debug view. If `pArray` is of type `void*` you can type `(char*) pArray, 10` which will display the content of the array interpreted as char. – VoidStar Aug 15 '13 at 09:26
-
1Cannot do this in Visual Studio 2008 Express. If I add an expression "a+1,2" in the Watch Window, the foloowing error will occur: "error: + cannot be performed on 'pArray' and '1'". What version of VS are you using? – An Cong Tran Jun 14 '14 at 17:03
-
-
4I think you're probably using GDB as the debugger in Eclipse, in which case the equivalent syntax, `*pArray@10` is what you're looking for. I haven't tried it in Eclipse, but it works in command-line GDB. – Tom Jun 13 '16 at 14:08
-
-
I don't think this is possible in c#, unfortunately. VS uses a far more robust set of format specifiers for c++ than it does for c# for some reason. https://learn.microsoft.com/en-us/visualstudio/debugger/format-specifiers-in-csharp?view=vs-2019 – arkon Sep 12 '19 at 05:15
If you have a large array and only want to see a subsection of the array you can type this into the watch window;
ptr+100,10
to show a list of the 10 elements starting at ptr[100]. Beware that the displayed array subscripts will start at [0], so you will have to remember that ptr[0] is really ptr[100] and ptr[1] is ptr[101] etc.

- 4,367
- 4
- 28
- 41
I use the ArrayDebugView add-in for Visual Studio (http://arraydebugview.sourceforge.net/).
It seems to be a long dead project (but one I'm looking at continuing myself) but the add-in still works beautifully for me in VS2010 for both C++ and C#.
It has a few quirks (tab order, modal dialog, no close button) but the ability to plot the contents of an array in a graph more than make up for it.
Edit July 2014: I have finally built a new Visual Studio extension to replace ArrayebugView's functionality. It is available on the VIsual Studio Gallery, search for ArrayPlotter or go to http://visualstudiogallery.msdn.microsoft.com/2fde2c3c-5b83-4d2a-a71e-5fdd83ce6b96?SRC=Home

- 603
- 6
- 11
-
Looks great but doesnt support VS2013?? VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products. Supported Products : Microsoft.VisualStudio.Pro Version : [10.0] Version : [11.0] Version : [12.0] Version : [14.0] – Gregory Sep 28 '14 at 07:44
-
2It should do! I developed it in VS2013! What version of VS2013 (service pack / edition) are you running? If you search for ArrayPlotter in the Extension Manager (in the Online section) do you see it available within there? – Rodney Thomson Oct 16 '14 at 04:11
-
Are you trying to view an array with memory allocated dynamically? If not, you can view an array for C++ and C# by putting it in the watch window in the debugger, with its contents visible when you expand the array on the little (+) in the watch window by a left mouse-click.
If it's a pointer to a dynamically allocated array, to view N contents of the pointer, type "pointer, N" in the watch window of the debugger. Note, N must be an integer or the debugger will give you an error saying it can't access the contents. Then, left click on the little (+) icon that appears to view the contents.

- 10,768
- 34
- 94
- 129
Hover your mouse cursor over the name of the array, then hover over the little (+) icon that appears.

- 272,464
- 47
- 358
- 399