<p>If you have a statically allocated array, the Visual Studio debugger can easily display all of the array elements.  However, if you have an array allocated dynamically and pointed to by a pointer, it will only display the first element of the array when you click the + to expand it.  Is there an easy way to tell the debugger, show me this data as an array of type Foo and size X?</p>

[{'answer_id': 75202, 'author': 'shoosh', 'author_id': 9611, 'author_profile': 'https://Stackoverflow.com/users/9611', 'pm_score': 9, 'selected': True, 'text': '<p>Yes, simple.\nsay you have</p>\n\n<pre><code>char *a = new char[10];\n</code></pre>\n\n<p>writing in the debugger:</p>\n\n<pre><code>a,10\n</code></pre>\n\n<p>would show you the content as if it were an array.</p>\n'}, {'answer_id': 75204, 'author': 'Drealmer', 'author_id': 12291, 'author_profile': 'https://Stackoverflow.com/users/12291', 'pm_score': 5, 'selected': False, 'text': '<p>In a watch window, add a comma after the name of the array, and the amount of items you want to be displayed.</p>\n'}, {'answer_id': 12477304, 'author': 'wog', 'author_id': 1022328, 'author_profile': 'https://Stackoverflow.com/users/1022328', 'pm_score': 0, 'selected': False, 'text': '<p>I haven\'t found a way to use this with a multidimensional array. But you can at least (if you know the index of your desired entry) add a watch to a specific value. Simply use the index-operator.</p>\n\n<p>For an Array named current, which has an Array named Attribs inside, which has an Array named Attrib inside, it should look like this if you like to have to position 26:</p>\n\n<pre><code>((*((*current).Attribs)).Attrib)[26]\n</code></pre>\n\n<p>You can also use an offset</p>\n\n<pre><code>((*((*current).Attribs)).Attrib)+25\n</code></pre>\n\n<p>will show ne "next" 25 elements. \n(I\'m using VS2008, this shows only 25 elements maximum).</p>\n'}, {'answer_id': 21000009, 'author': 'dabinsi', 'author_id': 3173933, 'author_profile': 'https://Stackoverflow.com/users/3173933', 'pm_score': 1, 'selected': False, 'text': '<p>For MFC arrays (CArray, CStringArray, ...)\nfollowing the next link in its Tip #4</p>\n\n<p><a href="http://www.codeproject.com/Articles/469416/10-More-Visual-Studio-Debugging-Tips-for-Native-De" rel="nofollow">http://www.codeproject.com/Articles/469416/10-More-Visual-Studio-Debugging-Tips-for-Native-De</a></p>\n\n<p>For example for "CArray pArray", add in the Watch windows</p>\n\n<pre><code>     pArray.m_pData,5 \n</code></pre>\n\n<p>to see the first 5 elements .</p>\n\n<p>If pArray is a two dimensional CArray you can look at any of the elements of the second dimension using the next syntax:</p>\n\n<pre><code>     pArray.m_pData[x].m_pData,y\n</code></pre>\n'}, {'answer_id': 22239703, 'author': 'gpliu', 'author_id': 337863, 'author_profile': 'https://Stackoverflow.com/users/337863', 'pm_score': 3, 'selected': False, 'text': "<p>a revisit:</p>\n\n<p>let's assume you have a below pointer:</p>\n\n<pre><code>double ** a; // assume 5*10\n</code></pre>\n\n<p>then you can write below in Visual Studio debug watch:</p>\n\n<pre><code>(double(*)[10]) a[0],5\n</code></pre>\n\n<p>which will cast it into an array like below, and you can view all contents in one go.</p>\n\n<pre><code>double[5][10] a;\n</code></pre>\n"}, {'answer_id': 25690207, 'author': 'Riaz Rizvi', 'author_id': 213307, 'author_profile': 'https://Stackoverflow.com/users/213307', 'pm_score': 5, 'selected': False, 'text': '<p>There are two methods to view data in an array m4x4:</p>\n\n<pre><code>float m4x4[16]={\n    1.f,0.f,0.f,0.f,\n    0.f,2.f,0.f,0.f,\n    0.f,0.f,3.f,0.f,\n    0.f,0.f,0.f,4.f\n};\n</code></pre>\n\n<p>One way is with a Watch window (Debug/Windows/Watch). Add watch =</p>\n\n<pre><code>m4x4,16\n</code></pre>\n\n<p>This displays data in a list:</p>\n\n<p><img src="https://i.stack.imgur.com/K54SJ.png" alt="enter image description here"></p>\n\n<p>Another way is with a Memory window (Debug/Windows/Memory). Specify a memory start address = </p>\n\n<pre><code>m4x4\n</code></pre>\n\n<p>This displays data in a table, which is better for two and three dimensional matrices:</p>\n\n<p><img src="https://i.stack.imgur.com/kBbEI.png" alt="enter image description here"></p>\n\n<p>Right-click on the Memory window to determine how the binary data is visualized. Choices are limited to integers, floats and some text encodings.</p>\n'}, {'answer_id': 28973224, 'author': 'Taylor Price', 'author_id': 3805, 'author_profile': 'https://Stackoverflow.com/users/3805', 'pm_score': 2, 'selected': False, 'text': '<p>Yet another way to do this is specified here in <a href="https://msdn.microsoft.com/en-us/library/75w45ekt.aspx" rel="nofollow">MSDN</a>.</p>\n\n<p>In short, you can display a character array as several types of string. If you\'ve got an array declared as:</p>\n\n<pre><code>char *a = new char[10];\n</code></pre>\n\n<p>You could print it as a unicode string in the watch window with the following:</p>\n\n<pre><code>a,su\n</code></pre>\n\n<p>See the tables on the MSDN page for all of the different conversions possible since there are quite a few. Many different string variants, variants to print individual items in the array, etc.</p>\n'}, {'answer_id': 31872247, 'author': 'Legolas', 'author_id': 109787, 'author_profile': 'https://Stackoverflow.com/users/109787', 'pm_score': 2, 'selected': False, 'text': '<p>You can find a list of many things you can do with variables in the watch window in this gem in the docs:\n<a href="https://msdn.microsoft.com/en-us/library/75w45ekt.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/75w45ekt.aspx</a></p>\n\n<p>For a variable a, there are the things already mentioned in other answers like </p>\n\n<pre><code>a,10 \na,su \n</code></pre>\n\n<p>but there\'s a whole lot of other specifiers for format and size, like: </p>\n\n<pre><code>a,en (shows an enum value by name instead of the number)\na,mb (to show 1 line of \'memory\' view right there in the watch window)\n</code></pre>\n'}, {'answer_id': 31900913, 'author': 'vicky', 'author_id': 3922508, 'author_profile': 'https://Stackoverflow.com/users/3922508', 'pm_score': 3, 'selected': False, 'text': '<p>For,</p>\n\n<pre><code>int **a; //row x col\n</code></pre>\n\n<p>add this to watch</p>\n\n<pre><code>(int(**)[col])a,row\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/75180', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9530/']