what is calloc and malloc?

Answers were Sorted based on User's Feedback



what is calloc and malloc?..

Answer / vadivel t

Hi Jhothi16,
how do u say calloc is for reallocation???..

Ans is,

Both are serving for the purpose of dynamic memory
allocation.
But malloc and calloc differs in two ways.

1.After allocating memory using malloc(), the data elements
in the memory will not be initialised. Means, it contains
garbage values.

But calloc() initialise all the data elements to 0.


2.malloc() allocates memory in terms of bytes.it accepts
only one argument, which says no of bytes to be allocated.

But calloc() allocates memory interms of blocks. it is
widely used when there is a need to allocated memory for an
array.

it accepts two arguments, 1st says, no of blocks to be
allocated and next argument says the size of the block.

ex:

calloc(10, sizeof(int))

-> it allocates 40 bytes, if the compiler allocates 4 bytes
for an int variable.

Is This Answer Correct ?    17 Yes 1 No

what is calloc and malloc?..

Answer / jothi16

calloc means reallocate the memory.malloc used to allocate
the memory

Is This Answer Correct ?    6 Yes 20 No

Post New Answer

More C Interview Questions

How can you increase the allowable number of simultaneously open files?

0 Answers  


HOW DO YOU HANDLE EXCEPTIONS IN C?

2 Answers   AppLabs,


Average of a couple 10 years ago was 25. The average remains same after having a child and twins after 3 years. What is the present age of the first child

10 Answers   IBM, Infosys,


I have an array of 100 elements. Each element contains some text. i want to: append a star character to the end of every fifth element remove every second character from every tenth element, and… add a line feed (ascii 10) after the 30th character of every array element whose length is greater than 30 characters.

1 Answers  


#include<stdio.h> int f(int,int); int main() { printf("%d",f(20,1)); return 0; } int f(int n,int k) { if(n==0) return 0; else if(n%2)return f(n/2,2*k)+k; else return f(n/2,2*k)-k; } how this program is working and generating output as 9....?

1 Answers  






typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

0 Answers  


Explain what is a pragma?

0 Answers  


How can I implement sets or arrays of bits?

0 Answers  


The program to allow the characters from the input received and send this function to a function check if the characters between letters a to z is a function of y joins as the characters main and output to otherwise return to the original function of the y characters

0 Answers  


Are the variables argc and argv are always local to main?

0 Answers  


WHAT IS RTGS N MINIMUM AMT TO B TRANSFERD N WHAT R THE CHARGES ON MINIMUM AMT N IN WHICH BANK WE CAN DO IT?

1 Answers  


What are the commands should be given before weiting C Program i.e, Cd.. like

4 Answers   IBM, Infonet, Satyam, Tech Mahindra,


Categories