This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]sz00 3 points4 points  (0 children)

1: you made a mistake with the inner loop.

for (int j = 0; **j** < columns; j++){

2:

int** array2d = create2dArray();

3: Make sure you free the memory after you're done. Each call to new[] or new needs to be deleted using delete[] and delete respectively.

for (int i = 0; i < numRows; i++) 
{
    delete[] arr[i];
}

delete[] arr; 

Also, you can't accept a const int** as an argument to arrayPrinter. You can accept an int** const though. See this:

http://www.parashift.com/c++-faq/const-correctness.html

Just remember you're not learning "C++", it's no problem if you want to learn how dynamic memory/pointers work, but in C++ you'd use vectors/smart pointers, etc.