WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?
Answers were Sorted based on User's Feedback
Answer / karthik
Malloc() is used to allocate a block of memory
Calloc() is used to allocate a block of memory and initialize it.
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / jayakrishnan d
1.malloc is only one argument function while malloc is a
two arguments function.
2.malloc allocates bytes of memory while calloc allocates
array of memory.
3.malloc does not initialize the size of allocated memory ie
gabage value while calloc is initialize size of allocated
memory to '0'.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / kaushik
malloc takes only one argument but calloc takes two orguments
malloc takes garbage value initial but calloc takes zero initial value,
calloc()and malloc() also returns NULL if there is not sufficient memory available in the heap
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / tinku
There are two differences.
First, is in the number of arguments.
Malloc() takes a single argument (memory required in bytes),
Calloc() needs two arguments.
Secondly, malloc() does not initialize the memory allocated, while
calloc() initializes the allocated memory to ZERO.
calloc() allocates a memory area, the length will be the product of its parameters. calloc fills the memory with ZERO's and returns a pointer to first byte. If it fails to locate enough space it returns a NULL pointer.
Syntax: ptr_var=(cast_type *)calloc(no_of_blocks , size_of_each_block);
i.e. ptr_var=(type *)calloc(n,s);
malloc() allocates a single block of memory of REQUSTED SIZE and returns a pointer to first byte. If it fails to locate requsted amount of memory it returns a null pointer.
Syntax: ptr_var=(cast_type *)malloc(Size_in_bytes);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / nazia wasim
malloc and calloc both are used to allocate
memory dynamically but the difference is
malloc allocates single block of memory and
calloc allocates multiple block of memory as
per the requirement.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / datta khilari
1.malloc() takes one argument and allocates memory in a
bytes and return to the pointer.
1.calloc() takes two argument and allocates memory in a
blocks and return to the pointer.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sudhir
malloc used to static memory allocation &
calloc is used to dyanmic memory allocation
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / shirish
malloc: malloc create the single block of given size by user
calloc: calloc creates multiple blocks of given size
| Is This Answer Correct ? | 1 Yes | 3 No |
What are the advantages of external class?
A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?
write a function to swap an array a[5] elements like a[0] as a[5],a[1] as a[4],....a[5] as a[0].without using more than one loop and use one array not to use temp array?
What is structure padding and packing in c?
What is the symbol indicated the c-preprocessor?
What is the restrict keyword in C?
what is data structure?
What is dynamic variable in c?
Explain what is output redirection?
Print all the palindrome numbers.If a number is not palindrome make it one by attaching the reverse to it. eg:123 output:123321 (or) 12321
What is meant by operator precedence?
Is that possible to add pointers to each other?