difference between malloc and calloc
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
n=7623 { temp=n/10; result=temp*10+ result; n=n/10 }
How do you write a program which produces its own source code as its output?
Write a program that his output 1 12 123
Explain what is the best way to comment out a section of code that contains comments?
What will happen when freeing memory twice
what will happen if you free a pointer twice after allocating memory dynamically ?
Can we use any name in place of argv and argc as command line arguments?
What is an example of structure?
Evaluate the following: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); 1) 10 2) 11 3) 1
HOW TO SWAP TWO NOS IN ONE STEP?
What is structure padding & expalain wid example what is bit wise structure?
What Is The Difference Between Null And Void Pointer?