All mock tests are FREE till 31 December — register to save your progress

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;
}

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D. free(p);

Explanation

Memory obtained with malloc is released with free(p).

More Programming Languages and Computer Graphics questions