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;
}
memfree(int p);
dealloc(p);
malloc(p, 0);
free(p);
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
25 comments Page 1 of 3.

Roddur said:   5 years ago
why are we doing malloc(.... sizeof(int*))?

It won't only (int ) do in place of (int *)?

Please anyone explain me.

Akash said:   6 years ago
How many bytes allocated ?

Sha Vat said:   6 years ago
Here, free() function is used to clear the memory that is dynamically created using calloc(), malloc() functions.

Ahmed said:   7 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!

Ahmed said:   7 years ago
Same problem here, why the type casting (int**)?

p = (int **) malloc(MAXROW * sizeof(int*));

Emanuel said:   7 years ago
I don't understand the casting (int**). The malloc function gives an address of memory where you can put an integer value, i.e., it is a pointer to an integer. How it can help a cutting that it points to a pointer to an integer. It, indeed, only a pointer to an integer?

Darshan kg said:   7 years ago
Malloc allocates a single block of memory but calloc allocates multiple blocks of memory. For calloc block, initial value will be zero.

Abhi said:   7 years ago
What is the advantage of malloc and calloc?

Amit said:   7 years ago
Please explain me how malloc works?

Abhishek said:   8 years ago
It is a pointer to a pointer, means it keeps the address of a pointer variable.

Ex: int *q, **p;

Then p = &q;


Post your comments here:

Your comments will be displayed after verification.