double **dptr;
dptr = new double*[5];
for (int i = 0; i < 5; i++)
dptr[i] = new double[3];
How many rows and columns will there be in dptr? Also, what would the code look like to Delete all the space allocated for dptr???
dptr = new double*[5];
// creates 5 rows
for (int i = 0; i < 5; i++)
dptr[i] = new double[3];
// creates 5 columns for each row.
// use the free() function to release memory
In the given code, `dptr` is a pointer to an array of pointers. Each element of `dptr` represents a pointer to an array of `double`.
So, there will be `5` rows (or elements in `dptr`) and each row will have `3` columns (or elements in `dptr[i]`).
To delete all the space allocated for `dptr`, you need to deallocate memory for each row and then delete the array itself.
Here's how you can delete the allocated memory:
```cpp
for (int i = 0; i < 5; i++)
delete[] dptr[i];
delete[] dptr;
```
Let's break it down step by step:
1. Iterate over each row using a loop starting from `0` and ending at `4` (since there are `5` rows).
2. Inside the loop, delete the memory allocated for each row using `delete[]` since `dptr[i]` represents an array.
3. After deleting the memory for all rows, outside the loop, delete the array itself using `delete[]` since `dptr` is also dynamically allocated.
By doing this, you will delete all the space allocated for `dptr`.