16. Consider the following code segment that dynamically allocates memory on the heap to create and use it as a matrix with 4 rows, and 3 columns: int **a new int* [4]; for (int i = 0; i <4; i++) { a[i] = new int [3]; for (int j 0; j < 3; j++) a[i] [j] = 0; Which one of the following statements is the proper way to de-allocate/remove the allocated memory from heap: for (int i = 0; i< 3; i++) a b с delete [] a [i]; delete [] a; delete [] a; for (int i = 0; i <4; i++) delete [] a[i]; for (int i delete [] a[i]; delete [] a; 0; i <4; i++) d delete [] a;

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question
16. Consider the following code segment that dynamically allocates memory on the heap to create and use it as a
matrix with 4 rows, and 3 columns:
int **a = new int* [4];
for (int i = 0; i <4; i++) {
a[i] = new int [3];
for (int j=0; j < 3; j++)
a[i][j] = 0;
Which one of the following statements is the proper way to de-allocate/remove the allocated memory from heap:
for (int i= 0; i < 3; i++)
delete [] a [i];
a
b
(
с
d
delete [] a;
delete [] a;
for (int i
0; i <4;i++)
delete [] a[i];
=
for (int i
delete [] a [i];
delete [] a;
delete [] a;
0; i < 4; i++)
Transcribed Image Text:16. Consider the following code segment that dynamically allocates memory on the heap to create and use it as a matrix with 4 rows, and 3 columns: int **a = new int* [4]; for (int i = 0; i <4; i++) { a[i] = new int [3]; for (int j=0; j < 3; j++) a[i][j] = 0; Which one of the following statements is the proper way to de-allocate/remove the allocated memory from heap: for (int i= 0; i < 3; i++) delete [] a [i]; a b ( с d delete [] a; delete [] a; for (int i 0; i <4;i++) delete [] a[i]; = for (int i delete [] a [i]; delete [] a; delete [] a; 0; i < 4; i++)
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning