what is calloc and malloc?

Answers were Sorted based on User's Feedback



what is calloc and malloc?..

Answer / vadivel t

Hi Jhothi16,
how do u say calloc is for reallocation???..

Ans is,

Both are serving for the purpose of dynamic memory
allocation.
But malloc and calloc differs in two ways.

1.After allocating memory using malloc(), the data elements
in the memory will not be initialised. Means, it contains
garbage values.

But calloc() initialise all the data elements to 0.


2.malloc() allocates memory in terms of bytes.it accepts
only one argument, which says no of bytes to be allocated.

But calloc() allocates memory interms of blocks. it is
widely used when there is a need to allocated memory for an
array.

it accepts two arguments, 1st says, no of blocks to be
allocated and next argument says the size of the block.

ex:

calloc(10, sizeof(int))

-> it allocates 40 bytes, if the compiler allocates 4 bytes
for an int variable.

Is This Answer Correct ?    17 Yes 1 No

what is calloc and malloc?..

Answer / jothi16

calloc means reallocate the memory.malloc used to allocate
the memory

Is This Answer Correct ?    6 Yes 20 No

Post New Answer

More C Interview Questions

Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer...

4 Answers   TCS,


Program to write some contents into a file using file operations with proper error messages.

2 Answers  


What is an object?

5 Answers  


main() { printf(5+"Vidyarthi Computers"); }

6 Answers  


Where static variables are stored in memory in c?

0 Answers  


Is fortran faster than c?

0 Answers  


create an SINGLE LINKED LISTS and reverse the data in the lists completely

3 Answers  


What are the 32 keywords in c?

0 Answers  


array of pointer pointer to array pointer to pointer

1 Answers   MAHINDRA,


How to add two numbers without using semicolon n c????

3 Answers  


What is the output of following program ? int main() { int x = 5; printf("%d %d %d\n", x, x << 2, x >> 2); }

5 Answers   Amazon, Qualcomm,


What is a loop?

0 Answers  


Categories