How will you free the memory allocated by the following program? #include…
2023
How will you free the memory allocated by the following program?
#include <stdio.h>
#include <stdlib.h>
#define MAXROW 3
#define MAXCOL 4
int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int *));
return 0;
}- A.
memfree(int p);
- B.
dealloc(p);
- C.
malloc(p,0);
- D.
free(p);
Attempted by 323 students.
Show answer & explanation
Correct answer: D
The code uses malloc to allocate memory dynamically. To prevent memory leaks, you must call free() with the pointer p before the program ends.
A video solution is available for this question — log in and enroll to watch it.