Hi,
I got the following code able to be compiled and built. But, it shows a runtime error. Also, I am not sure the meaning of some code. Anyone could explain them and how can I fix the runtime error?
Thanks for help.
gogo
#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
using namespace std;
int main()
{
const int row = 4;
const int col = 4;
int** ppint; //2-D array ptr
ppint = new int*[row]; // Don't understand?? new space for 4x4 elements
for (int i=0; i<row; i++)
ppint[i]=new int(col); //Does it create the space for the col of each row?
for (int j=0; j<row; j++)
for (int k=0; k<col; k++)
ppint[j][k]=0; //initialize all elements
ppint[0][0]=ppint[1][1]=ppint[2][2]=ppint[3][3] = 1;
for (int m=0; m<row; m++)
{
for (int n=0; n<col; n++)
cout << ppint[m][n] << ' ';
cout << endl;
}
for (int a=0; a<row; a++)
delete [] ppint[a]; //What does it mean? to delete the memory of all rows?
delete [] ppint; //Does it delete all col's elements?
return 0;
}