Explain the difference between malloc() and calloc() in c?



Explain the difference between malloc() and calloc() in c?..

Answer / Rahul Shastri

Both malloc() and calloc() are used to dynamically allocate memory in C. The main difference is that calloc() initializes the allocated memory with zeroes, while malloc() does not. Also, calloc() takes into account the number of elements being allocated, making it more convenient for arrays.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is Bitwise Operator and how it works?

1 Answers  


What is a list in c?

1 Answers  


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

1 Answers  


for (i <= 5 && i >= -1;++i; i > 0) { printf("%d ", i); }

1 Answers  


Is there any data type in c with variable size?

1 Answers  


#include<conio.h> #include<stdio.h> void main() { int i; if(1,0,2,3) { printf("if"); } else { printf("else"); } getch(); } Can any body tell the answer of this question with explanation?

3 Answers   Huawei,


Switch (i) i=1; case 1 i++; case 2 ++i; break; case 3 --i; Output of i after executing the program

5 Answers   Mascot,


What math functions are available for integers? For floating point?

1 Answers  


What is a structure member in c?

1 Answers  


study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above

15 Answers   Accenture, TCS,


Can we increase size of array in c?

1 Answers  


write a program to display all prime numbers

1 Answers  


Categories