Question: Why is the memory leaking C++. void printboard(int rows, int cols, char** Board) { int i, j; cout < < endl; for (i = 0;

Why is the memory leaking C++.

void printboard(int rows, int cols, char** Board) {

int i, j;

cout << endl;

for (i = 0; i < cols; ++i) {

if (i < 10) {

cout << " " << i+1 << " ";

}

else

cout << " " << i+1 << " ";

}

cout << " ";

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

if (i % 2 == 0 && j % 2 == 0)

cout << "|\033[30;47m " << Board[i][j] << " ";

else if (i % 2 == 1 && j % 2 == 1)

cout << "|\033[30;47m " << Board[i][j] << " ";

else

cout << "|\033[0m " << Board[i][j] << " ";

cout << "\033[0m";

}

cout << endl;

}

}

void deletearr(char** board, int rows, int cols) {

for (int y = 0; y < rows; y++) {

delete[] board[y];

board[y] = NULL;

}

}

void initarr(char*** Board, int rows, int cols) {

*Board = new char* [(rows + 1)];

for (int i = 0; i <= rows; ++i)

(*Board)[i] = new char[cols];

for (int i = 0; i <= rows; ++i) {

for (int j = 0; j < cols; ++j) {

(*Board)[i][j] = ' ';

}

}

}

int main() {

char **Board = NULL;

int rows = 5;

int cols = 5;

int var;

initarr(&Board, rows, cols);

while (1) {

printboard(rows, cols, Board);

cout << ":";

cin >> var;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!