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.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
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
Click here
to improve the Interview Question, Answer and other fields.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
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
Click here
to improve the Interview Question, Answer and other fields.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
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
Click here
to improve the Interview Question, Answer and other fields.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
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
Click here
to improve the Interview Question, Answer and other fields.