what is the difference between malloc , calloc and realloc?
what r their uses?
rohoni
0
Newbie Poster
Recommended Answers
Jump to Postmalloc returns a block of memory that is allocated for the programmer to use, but is uninitialized. calloc allocates memory and then initializes it. realloc is used to grow or shrink a block of memory.
Jump to Postmalloc returns the blocks in random way(dynamic)
calloc returns the blocks in sequencial way means one after another
realloc is used to minimise already allocated memory blocks or maximize the sameThat's the dumbest thing I've read all morning. But it's early, so I'm sure someone will come up with …
Jump to Postint *p,*a; p=(int*)malloc(sizeof(int)); a=(int*)malloc(sizeof(int));
here memory need not to be contiguous.
int *p; p=(int*)malloc(5*sizeof(int));
here memory allocation must be contiguous.
Are you an idiot? How does calling malloc() twice somehow dispute my statement that the bytes allocated by malloc() are required to be contiguous? Further, how does …
All 11 Replies
plgriffith
0
Junior Poster
Bhushan2987
-4
Newbie Poster
WaltP
commented:
You resurrected a 2 year old thread for this incorrect information? Great!
-4
asitmahato
-4
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
WaltP
commented:
yeah, and it's 3.5 years after the fact, too.
+17
cse.avinash
-1
Junior Poster
WaltP
commented:
How many times do we have to restate the same information answering a 3.5 year old thread?
-4
asitmahato
-4
Newbie Poster
WaltP
commented:
How many times do we have to restate the same information answering a 3.5 year old thread?
-4
Narue
5,707
Bad Cop
Team Colleague
asitmahato
-4
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
asitmahato
-4
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.