Thursday, March 25, 2010

Viewing all elements of dynamically allocated arrays In VC++

Normally when we allocate an array dynamically, and when we look at the variable in the watch window you can only see the first element. To view the entire array just type the , .

Example:

void main( void )
{
const int SIZE = 10;
int *intArray = 0;

intArray = (int *)malloc( sizeof( int ) * SIZE ) ;

for( int x = 0; x < SIZE; x++ )
{
intArray[x] = 10 + x;
}

return 0; // put a break point here, so that control stops here and
// we can see the "intArray" contents in "Watch" window
}


Watch Window: Debug -> Windows -> Watch ->

to see intArray in the watch window type

intArray, 10

and now we can see all the 10 elements of "intArray" in watch windows.

No comments: