What's the difference between calloc() and malloc()?
Answers were Sorted based on User's Feedback
Answer / guest
calloc() takes two arguments, and initializes the allocated
memory to all-bits-0.
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / k.thejonath
Malloc allocates a block of memory whereas using calloc we
can allocate array of memory blocks and all locations are
initialized to zeros
| Is This Answer Correct ? | 5 Yes | 3 No |
Answer / valli
the diffence is
1.prototype or no of arguments
calloc takes two arguments
where as malloc takes 1 argument
void *calloc(int ,int);
first argument is no of blocks required
secund argument is no of elementts in each block required
void *malloc(int);
in this total no of bytes reuired are taken as the argument
2.
calloc clears the bytes which are allocated or reserved
where malloc can not guarentee this
sorry for my poor english
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / bhaswati
malloc allocates m bytes means it takes one arguments.but calloc allocate m times n bytes and initialized the memory location to zero.it takes two arguments.
| Is This Answer Correct ? | 0 Yes | 0 No |
program for following output using for loop? 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5
main() { int x=5,y=10,z=0; x=x++ + y++; y=y++ + ++x; z=x++ + ++y; printf("%d%d%d\n",x,y,z); }
I didn't count the ducks that I saw in line, but I do remember that one duck was in front of two ducks, another duck behind two ducks. How many ducks did I see?
how to write hello word without using semicolon at the end?
Explain function pointer with exapmles.
write a program to check whether a given integer is a strong number or not? [Hint: 145=1!+4!+5! =1+24+120 =145]
Write a program of advanced Fibonacci series.
Is a house a shell structure?
What is the mean of function?
main() { int age; float ht; printf("Enter height and age"); scanf("%d%d",&height,&age); if((age<=20)&&(ht>=5)) {printf("She loves you");} else {printf("She loves you");} }
How to implement a packet in C
How is null defined in c?