JoeyAdams |
08-26-2007 02:23 PM |
First of all, get in the habit of freeing the arrays you make:
Code:
//free the array
for (int i=0; i<10; i++)
{ delete[] array[i]; }
delete[] array;
If you do this now, your program will crash because it isn't written correctly. When you say (*array)++; , that is the same as array[0]++, meaning increment the pointer at array[0]. You are trailing array[0] out way after its original location, so when you go to free it, the program will crash. Also, note the order of operations. [] comes before *, so when you say:
*array[j]=0;
That means *(array[j]), NOT (*array)[j] What you probably meant to write for each loop is this:
Code:
//print the 2D array in 10-group values
cout << "2D array BEFORE 0 INITIALIZATION" <<endl;
for (int i=0; i<10; i++)
{
for (int j=0; j<10; j++)
{
printf("%i",(*array)[j]);
}
cout<<endl;
array++;
}
array-=10; /* important! We iterated through the array by
adding one 10 times, so we need to subtract 10 so the pointer will
be back where it was when we do anything else with it. */
|