difference between malloc and calloc

Answers were Sorted based on User's Feedback



difference between malloc and calloc..

Answer / namita

1-memory allocated by malloc contains garbage value.But
memory allocated by calloc is initialised to zero.

2-malloc takes only one argument which indicates the size
to be allocated.But calloc takes two arguments.First
argument indicates the number of blocks to be allocated
where as the second argument indicates the size of the
block.

Is This Answer Correct ?    35 Yes 2 No

difference between malloc and calloc..

Answer / vara

There are two differences.
1) is the number of arguments. Malloc() takes a single
argument (memory required in bytes), while calloc() needs
two arguments (number of variables to allocate memory, size
in bytes of a single variable).
2)malloc() does not initialize the memory allocated, while
calloc() initializes the allocated memory to ZERO.

Is This Answer Correct ?    15 Yes 2 No

difference between malloc and calloc..

Answer / bijaya

1)malloc() function does not initialize the memory which it
allocates thats why it takes the garbage value.but calloc()
function initializes the allocated memory to zero thats why
it cant take any garbage value.

2)malloc() function takes single arg.that is the variabe
which is used to indicate the memory size to be
allocated.calloc() function takes two args-i) variable which
indicates the number of memory blocks.ii)variable which
indicates the size of each blocks.

Is This Answer Correct ?    7 Yes 0 No

Post New Answer

More C Interview Questions

Does c have function or method?

0 Answers  


Write a code of a general series where the next element is the sum of last k terms.

0 Answers   Aspiring Minds,


What is a memory leak? How to avoid it?

1 Answers  


How to reverse a linked list

1 Answers   Aricent, Fidelity, IBM, TCS,


Differentiate Source Codes from Object Codes

1 Answers  






Explain what is a stream?

0 Answers  


Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning

4 Answers   Accenture,


What are the main characteristics of c language describe the structure of ac program?

0 Answers  


Explain what is meant by high-order and low-order bytes?

0 Answers  


Explain how do I determine whether a character is numeric, alphabetic, and so on?

0 Answers  


what are the stages of compilation

1 Answers   Bosch,


write a c program to convert fahrenheit to celsius?

4 Answers   TCS,


Categories