C Programming - Memory Allocation - Discussion
Discussion Forum : Memory Allocation - General Questions (Q.No. 1)
1.
Which header file should be included to use functions like malloc() and calloc()?
Discussion:
37 comments Page 2 of 4.
Gmdn said:
1 decade ago
malloc is called from user space. stdlib contains the extern declarations needed for malloc. The definition if malloc is present in stdlib (may be glib) which intern calls "brk".
This is system call which in calls sys_brk. This extends the heap memory by specified memory size.
This is system call which in calls sys_brk. This extends the heap memory by specified memory size.
Anusha said:
1 decade ago
Yes, @Abhay is correct. Malloc, calloc, realloc and free functions are for dynamic memory allocation, which are stored in heap section. And in stdlib.h header file.
Girija sankar said:
10 years ago
I think it should be alloc.h. But it is not in the options. We can prefer standard library i.e (stdlib.h).
Saddam said:
9 years ago
According to me malloc() and calloc() is dynamic memory allocation.
Ashwini said:
9 years ago
Hi, friends.
What is brk & sys_brk? Please explain briefly.
What is brk & sys_brk? Please explain briefly.
Vishalakshi said:
9 years ago
I think malloc is better than calloc. Because calloc initialize all its elements to be zero, when memory is allocated. so when you want to insert '0' value in that memory location ,if you want to count the how many times '0' is repeated ,it counts all initialized value and inserted value. so it gives unexpected result.
So malloc is better.
So malloc is better.
Mohan rsm said:
8 years ago
The malloc() and calloc() are two library fuctions to allocate memory in language c. To allocate a block of memory, call malloc & calloc. The prototype for this function is in 'stdlib.h'.
Suresh said:
8 years ago
What is the stdib header file can you explain this?
Harsh said:
7 years ago
Basically, stdlib.h is a standard C header that includes malloc and calloc and free as well.
Kunjal said:
1 decade ago
Both allocate storage memory but the difference is malloc process single argument so just specify storage space while calloc process double argument so specify no. Of variable and space needed for that variable.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers