Which is better between malloc and calloc?



Which is better between malloc and calloc?..

Answer / Jaiprakash

"Both 'malloc' and 'calloc' are used for dynamic memory allocation in C. 'malloc' simply allocates a block of memory without initializing it, while 'calloc' initializes the allocated memory to zero. When you need uninitialized memory, use malloc. If you require memory with all elements initialized to zero, use calloc."n

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What are the languages are portable and platform independent?Why they are like that?

1 Answers   Excel, Satyam,


Why dont c comments nest?

1 Answers  


How can I write a function analogous to scanf?

1 Answers  


Which is the best sort method for library management?

1 Answers   Microsoft,


what is memory leak?

3 Answers  


Why is sizeof () an operator and not a function?

1 Answers  


What is sizeof int?

1 Answers  


Write a simple code fragment that will check if a number is positive or negative.

1 Answers  


Write a C function to search a number in the given list of numbers. donot use printf and scanf

6 Answers   Honeywell, TCS,


To what value do nonglobal variables default? 1) auto 2) register 3) static

4 Answers  


How can I recover the file name given an open stream?

1 Answers  


How do I create a directory? How do I remove a directory (and its contents)?

1 Answers  


Categories