Top

Discussion

How will you free the memory allocated by the following program?

#include 
#include  
#define MAXROW 2
#define MAXCOL 3
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);

Answer: D

Dynamically allocated memory created with either calloc() or malloc() doesn't get freed on their own. You must explicitly use free() to release the space.

No comment is present. Be the first to comment.
Loading…

Post your comment