Question & Additional Information
 
standard etrade question what is the difference between malloc and calloc ?
Add to My IQ
 

Answer Title
Answer

This is a very interesting and interviewers favourite for C
both are memory allocation functions

malloc is system call

calloc is c library call

when malloced the memory is uninitialised

when calloced the memory is initialised to all 0's

For malloc we specify the number of bytes
for calloc we specify  the number * datatype.

Question Tag Title
Tags
None
Question Asked At Title
Asked At
None
Question Job Title
Job Titles
None


Check out our newest job listings!

Post a Job! $49 for 60 days



Your Name:
Add your comment text
 
Related Questions
Related Questions
Flag this interview question as inappropriate Inappropriate
See Answer
The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.
Create Date
:
Sunday, April 27, 2008
Tags
:
Asked At
:
None
Job Positions
:
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer
Be honest but do not spend a lot of time in this area. Keep the focus on this job and what you can do for this organization. Anything else is a distraction
Create Date
:
Friday, March 21, 2008
Asked At
:
None
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer
sizeof(0) returns the size of integer whose value is 0. Hence malloc would allocate sizeof(int) bytes and return a valid pointer.
Create Date
:
Sunday, March 16, 2008
Tags
:
Asked At
:
None
Job Positions
:
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer
while programming if the memory is allocated by malloc of calloc but free() is not called at the end
of usage of the memory chunk, it remains allocated..and can be dangerous..
these are very important in case of development of large products..
often programers do not intentionally leave the memory allocated..but there may be situation
when the control is passed to a different portion of code and needs to be freed there

Memory leaks are extremely dangerous...
Create Date
:
Tuesday, January 15, 2008
Tags
:
None
Asked At
:
None
Job Positions
:
None
Click here to improve the Interview Question, Answer and other fields.
Comments (0) :
Goto add your comment on the Question 
Flag this interview question as inappropriate Inappropriate
See Answer

 

 

Create Date
:
Monday, September 24, 2007
Tags
:
Job Positions
:
Click here to improve the Interview Question, Answer and other fields.
Comments (2) :
1.
dk123
Wednesday, March 19, 2008 6:27 AM
nice comment
2.
thingMaster
Tuesday, October 23, 2007 1:52 PM
you are overconfident. you will probably kill many patients, but drive a nice car.
 
• More Related Questions: 
Suggestions & Comments




Share Your Interview Questions
Ask Interview Questions
View Unanswered Questions





Advertise on this site