Answer the question
In order to leave comments, you need to log in
How to correctly pass a two-dimensional dynamic array to a function?
The error occurs 0xC0000005 when the function works at the moment of assigning a value to a cell of an array.
#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 << "Введите столбцы - ";
cin >> rows;
cout << "Введите строки - ";
cin >> cols;
int** pmatr = new int* [rows];
Foo(pmatr, rows, cols);
for (int i = 0; 0 < rows; i++)
delete[] pmatr[i];
delete[] pmatr;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question