C Programming - Memory Allocation - Discussion
Discussion Forum : Memory Allocation - General Questions (Q.No. 3)
3.
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;
}
Discussion:
25 comments Page 3 of 3.
Ahmed said:
9 years ago
Same problem here, why the type casting (int**)?
p = (int **) malloc(MAXROW * sizeof(int*));
p = (int **) malloc(MAXROW * sizeof(int*));
Ahmed said:
9 years ago
I knew the answer, the type casting in malloc because malloc returns a void pointer. So we should type cast it to the type we want to use first!
Sha Vat said:
8 years ago
Here, free() function is used to clear the memory that is dynamically created using calloc(), malloc() functions.
Akash said:
8 years ago
How many bytes allocated ?
(1)
Roddur said:
7 years ago
why are we doing malloc(.... sizeof(int*))?
It won't only (int ) do in place of (int *)?
Please anyone explain me.
It won't only (int ) do in place of (int *)?
Please anyone explain me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers