JonTheBaller
Golden Member
How do I initialize a double pointer of type int (2D matrix) in C (**foo)?
Is new part of the C++ language?
Is new part of the C++ language?
Originally posted by: dighn
new and delete are C++ keywords. and it realy should be delete [] in those cases.
also int **pMatrix = new int [num_rows]; should really be = new int*[num_rows];
instead use int **pMatrix = (int*)malloc(sizeof(int*) * num_rows);
and free() instead of delete
Originally posted by: johnnytightlips
Originally posted by: dighn
new and delete are C++ keywords. and it realy should be delete [] in those cases.
also int **pMatrix = new int [num_rows]; should really be = new int*[num_rows];
instead use int **pMatrix = (int*)malloc(sizeof(int*) * num_rows);
and free() instead of delete
Do I still need to use the for loop to allocate the "inner" array?
Originally posted by: singh
Example:
const int num_rows = 5;
const int num_cols = 5;
int **pMatrix = new int [num_rows];
for(int i=0; i < num_rows; ++i)
{
pMatrix = new int [num_cols];
}
To Delete:
for(int i=0; i < num_rows; ++i)
{
delete pMatrix[ I ];
}
delete pMatrix;
new and delete are C++ keywords. and it realy should be delete [] in those cases.