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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started