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 2 of 3.

Siddu said:   1 decade ago
**p means?

CHINNA DURAI.S said:   1 decade ago
Why we use C program in mostly?

Jhansi said:   1 decade ago
In that program I want to meaning of p=(int**)malloc(MAXROW*sizeof(int*)).

Anju said:   1 decade ago
Can you please explain what is the meaning of

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

Vahitha said:   1 decade ago
What is the difference between alloc(), malloc(), calloc(), please give the clear idea?

Kirthi said:   1 decade ago
dealloc() functions can free the memory space right?

Sham said:   1 decade ago
Please explain about calloc( ) and malloc( )?

Manojkumar said:   1 decade ago
Yeh any allocation functions like alloc() , malloc() and calloc() should release their memory space with free() function only.

Vishal Dalawai said:   1 decade ago
@Murugan.

Below i have wrote code for memory allocation & free for 2-D array(3 Rows, 4 Columns)

#include<stdio.h>
#include<stdlib.h>

#define ROW 3
#define COL 4

int main()
{
int i;
int **arr;

// Memory allocation for Rows..
arr = (int**)malloc(ROW*sizeof(int*));
if(arr == NULL)
{
printf("Memory allocation for Row failed..\n");
exit(1);
}

// Memory allocation for Columns..
for(i=0; i<ROW; i++)
{
arr[i] = (int*)malloc(COL*sizeof(int)); // each row having 4 cols
if(arr[i] == NULL)
{
printf("Memory allocation for Column Elements failed..\n");
exit(1);
}


// Memory Free..
for(i=0; i<ROW; i++)
free(arr[i]);

free(arr);

return 0;

}

Murugan said:   1 decade ago
Can you write a simple program of memory allocation?


Post your comments here:

Your comments will be displayed after verification.