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

can any one tell that i have a variable which is declared as static but i want this variable to be visible to the other files? how?

2 Answers  


What are data breakpoints?

3 Answers   Adobe,


4)What would be the output? main() { int num=425; pf("%d",pf("%d",num)); } a)Comp error b)4425 c)4253 d)3435 e)none

10 Answers  


What is diffrance between declaration and defination of a variable or function

4 Answers  


What is conio h in c?

0 Answers  






Can I pass constant values to functions which accept structure arguments?

2 Answers  


#include <stdio.h> #define sqr(x) (x*x) int main() { int x=2; printf("value of x=%d",sqr(x+1)); } What is the value of x?

16 Answers   Accel Frontline, Opera, Oracle,


What is this infamous null pointer, anyway?

0 Answers  


Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......

0 Answers  


How to print "Hi World" without using semi colon?

6 Answers   Infosys,


What is data type long in c?

0 Answers  


what is self refrential structure

3 Answers   HCL,


Categories