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

What are local static variables?

1 Answers  


in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none

1 Answers  


What is pointer to pointer in c language?

1 Answers  


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

1 Answers   TCS,


#include<stdio.h> void main() { int =1; printf("%d%d%d",a++,++a,++a); }

3 Answers   VB,


Explain demand paging.

1 Answers   Agilent,


i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....

1 Answers   RBI,


how would a 4*3 array A[4][3] stored in Row Major Order?

0 Answers   HCL, Ignou,


how can f be used for both float and double arguments in printf? Are not they different types?

1 Answers  


The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none

1 Answers  


Can we write a program without main() function?

9 Answers  


can you change name of main()?how?

3 Answers   HCL, Siemens,


Categories