I looked into two different method to allocate memory for the elements of a matrix
Method n.1
int** matrix = new int*[rows];
for (int i = 0; i < rows; ++i)
matrix[i] = new int[cols];
Method n.2
int** matrix = new int*[rows];
if (rows)
{
matrix[0] = new int[rows * cols];
for (int i = 1; i < rows; ++i)
matrix[i] = matrix[0] + i * cols;
}
I can figure out what Method n.1 does, but I can't figure out what exactly is supposed to do the if clause in Method n.2 (I would implement it without and it doesn't work, with the if clause, it does...)
EDIT: Here is a code showing my problem. Why does it take so long to load (~30seconds)?
Codepad refuses to show the output (timeout) so if you want to run it, just compile it on your own.
Also, why cout << statements are not executed once the program starts?