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 1 of 4.
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.
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.
Gayathri said:
1 decade ago
It is the files which helps us to use some library files in our program. And number of files are pre-created and stored as header file. We can use those files by giving the line #include<stdio.h>
".h" is the extension of header file.
".h" is the extension of header file.
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.
Sundar said:
1 decade ago
We can include any of the following header files
1. stdlib.h
2. alloc.h
Since alloc.h is not provided in any option. Therefore stdlib.h is the correct answer.
Hope this help you. Have a nice day!
1. stdlib.h
2. alloc.h
Since alloc.h is not provided in any option. Therefore stdlib.h is the correct answer.
Hope this help you. Have a nice day!
Janardan said:
1 decade 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'.
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'.
Anjireddy said:
1 decade ago
calloc(), malloc(), realloc(), free() are the functions for used for dynamic allocation of memory. So, They are predefined functions we can use them by including stdlib.h.
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.
Anubhav Singh said:
1 decade ago
we know that stdlib is standard library which include mostly all segments of header files it is like an package, which contains these like alloc.h, malloc.h etc.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers