C Programming - Memory Allocation - Discussion

1. 

Which header file should be included to use functions like malloc() and calloc()?

[A]. memory.h
[B]. stdlib.h
[C]. string.h
[D]. dos.h

Answer: Option B

Explanation:

No answer description available for this question.

Janardan said: (Oct 4, 2010)  
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'.

Wahid Sayed said: (Oct 20, 2010)  
Then when do we use memory.h ?

Likita Shetty said: (Jan 7, 2011)  
I thought its just "alloc.h" .. i remember my program working by using just alloc.h

Mahesh said: (Jan 21, 2011)  
The header file will be alloc.h but it is not in the option.

Sundar said: (Jan 21, 2011)  
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!

Ruthran said: (Mar 1, 2011)  
stdlib.h header file only have prototype of malloc() and clloc()

Anubhav Singh said: (Jun 19, 2011)  
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.

Gudevenkatrao said: (Jul 30, 2011)  
What is the syntax of malloc() ?

Latha said: (Aug 24, 2011)  
Give difference of malloc & calloc ?

Kunjal said: (Sep 30, 2011)  
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.

Sunil said: (Jun 28, 2012)  
malloc() simply assigns a memory block to a pointer while calloc() assign block as well as in initialize all its elements to zero.

Ravindra said: (Jul 31, 2012)  
Which one is better out of malloc() and calloc() to allocate memory for a variable ? Can any one please explain this ?

Soundarya Kumari.B said: (Oct 3, 2012)  
C dynamic memory allocation refer to perform the dynamic memory allocation is present in standard library namely malloc(), calloc(), realloc().

Muskaan said: (Jan 16, 2013)  
int *x;
x = (int *)malloc(n * sizeof(int));
This will allocate n element array of int type elements.

Arti Dixit said: (Feb 26, 2013)  
How many prototype related to memory allocation?

Ravi said: (Aug 27, 2013)  
What is a header file?

Gayathri said: (Aug 30, 2013)  
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.

Abhayraj said: (Nov 5, 2013)  
malloc, calloc, realloc, free are functions used 4 dynamic memory allocation. 4 such functions we should include header file of standard library (stdlib.h).

Anusha said: (Dec 31, 2013)  
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.

Ganesh said: (Jul 2, 2014)  
What is mean by malloc, calloc and realloc explain with simple example?

Kumar Mani said: (Jul 25, 2014)  
calloc() is better than malloc().

Anjireddy said: (Aug 21, 2014)  
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.

Vinutha said: (Nov 5, 2014)  
What is free ();?

Ashu said: (Nov 23, 2014)  
How calloc() is better than malloc? Explain with a example?

Bittubohemia said: (Mar 2, 2015)  
How memory can be allocate in android? Can anyone explain?

Akash Patel said: (Mar 4, 2015)  
How we will decide which one is better calloc or malloc during memory allocation?

Yogeshkumar said: (Mar 8, 2015)  
stdlib.h is the header file which contain predefine prototype for malloc() & calloc().

Gmdn said: (Apr 20, 2015)  
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.

Arathy S V said: (Oct 8, 2015)  
How malloc and calloc stored in heap section?

Girija Sankar said: (Dec 10, 2015)  
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: (Mar 17, 2016)  
According to me malloc() and calloc() is dynamic memory allocation.

Ashwini said: (Apr 5, 2016)  
Hi, friends.

What is brk & sys_brk? Please explain briefly.

Vishalakshi said: (Nov 30, 2016)  
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.

Mohan Rsm said: (Jul 11, 2017)  
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: (Aug 19, 2017)  
What is the stdib header file can you explain this?

Vicky Karn said: (Oct 26, 2017)  
malloc(), calloc(), realloc() n free(), all are defined in stdlib.h as well as alloc.h
We can include anyone.

Regarding option, stdlib.h is the answer.

Harsh said: (Aug 4, 2018)  
Basically, stdlib.h is a standard C header that includes malloc and calloc and free as well.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.