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.
Abhayraj said:
1 decade ago
malloc, calloc, realloc, free are functions used 4 dynamic memory allocation. 4 such functions we should include header file of standard library (stdlib.h).
Vicky Karn said:
8 years ago
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.
We can include anyone.
Regarding option, stdlib.h is the answer.
(1)
Soundarya kumari.b said:
1 decade ago
C dynamic memory allocation refer to perform the dynamic memory allocation is present in standard library namely malloc(), calloc(), realloc().
Sunil said:
1 decade ago
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:
1 decade ago
Which one is better out of malloc() and calloc() to allocate memory for a variable ? Can any one please explain this ?
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).
Muskaan said:
1 decade ago
int *x;
x = (int *)malloc(n * sizeof(int));
This will allocate n element array of int type elements.
x = (int *)malloc(n * sizeof(int));
This will allocate n element array of int type elements.
Likita shetty said:
1 decade ago
I thought its just "alloc.h" .. i remember my program working by using just alloc.h
Harsh said:
7 years ago
Basically, stdlib.h is a standard C header that includes malloc and calloc and free as well.
Yogeshkumar said:
1 decade ago
stdlib.h is the header file which contain predefine prototype for malloc() & calloc().
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers