How to pass two dimensional dynamic array to a function?

0xC0000005 error occurs when running a function at the time of the assignment cell of the array values.

#include <cstdlib>
#include <iostream>

using namespace std;




void Foo(int** matrix, int const rows, int const cols)
{
 for (int i = 0; i < rows; i++)
{
 cout << "\n"; 
 for (int j = 0; j < cols; j++)
{
 matrix[i][j] = 1;
 cout << "\t";

}
}
}

int main()
{
 int rows = 0;
 int cols = 0;
 cout << "Enter columns ";
 cin >> rows;
 cout << "Enter string ";
 cin >> cols;
 int** pmatr = new int* [rows];
 Foo(pmatr, rows, cols);

 for (int i = 0; 0 < rows; i++)
 delete[] pmatr[i];
 delete[] pmatr;
}
April 7th 20 at 15:20
2 answers
April 7th 20 at 15:22
Solution
In With++ the two-dimensional dynamic array is passed to a function like this:
void Foo(std::vector< std::vector <int> > &matrix)
And Masturbation with arrays of pointers is spaghetti and guaranteed leak and segfault.
This vectors.
Two-dimensional dynamic array is somewhat different.

And Masturbation with arrays of pointers is spaghetti and guaranteed leak and segfault.

The Linux kernel developers tell us (although it eventually happened). - Cassandra_Wintheis commented on April 7th 20 at 15:25
@Orrin, I wrote how it is different.
By the way, still in the assembler listing, the difference is not so big.
Here's a leg injury when a shot is downright critical are different, Yes. - Andre_Harb commented on April 7th 20 at 15:28
@alfred_Feil,
I wrote how it is different.

Where?

In With++ the two-dimensional dynamic array is passed to a function like this:
void Foo(std::vector< std::vector > &matrix)
And Masturbation with arrays of pointers is spaghetti and guaranteed leak and segfault.
- Cassandra_Wintheis commented on April 7th 20 at 15:31
@Orrin, Oh yeah, I forgot to clarify. I wrote for those who can read, and not just to get. - Andre_Harb commented on April 7th 20 at 15:34
@Orrin, strictly speaking, it is the canonical and recommended way in C++. Well, or a class like Matrix.
The problem is that many people still programming in "C with classes" not C++, while C and C++ are two completely different languages with different applications. - winston commented on April 7th 20 at 15:37
@whitney.Swaniawsif on C With classes... high school manuals and their pathetic labs are still taught the language Spaghetti++. Here as in the vehicle. - Andre_Harb commented on April 7th 20 at 15:40
April 7th 20 at 15:24
Solution
int** pmatr = new int* [rows];

Where is the code for the two-dimensional array? See columns and rows where? Their cycle is generated.

Find more questions by tags C++