WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?
Answers were Sorted based on User's Feedback
Answer / monalisa dhal samanta
malloc() is a allocated 1 unit data type.it is a one argument
function .malloc allocate bytes of memory .
calloc() is a allocated sizeof data type .it is a two
argument .
Is This Answer Correct ? | 8 Yes | 3 No |
Answer / priya
malloc() allocates bytes of memory for a single block
whereas calloc() allocates blocks of memory for multiple
blocks
Is This Answer Correct ? | 8 Yes | 3 No |
Answer / vijay r15
malloc creates the
single block of gn
size by user. Malloc
takes 1ly 1 arg.
Calloc creates
multiple block of gn
size. It will
initialize the
reserved memory block
to zero. Calloc takes
2 arguments
Is This Answer Correct ? | 7 Yes | 2 No |
Answer / dilip k. singh(dks)
Malloc:
1. Takes only 1 argument- the size of the memory block to
be allocated.
2. Allocates memory as a single contiguous block.
3. Will fail if a single contiguous memory block of
required size is not available.
Calloc:
1. Takes two arguments - the number of memory blocks needed
and the size of each memory block.
2. It may or may not allocate a single contiguous block,
thus will not fail if a single contiguous memory block
of required size is not available.
3. Initialises the memory blocks to 0.
sUMMARY:
malloc() allocates 1 unit(datatype) of memory each time it
is called so to allocate memory for a file read char by
char allocating memory each time for a char till EOF.
calloc allocates sizeof(datatype) bytes to the no of
elements in the file, where by the user can specify the
file size as the second arguement.
char *malloc(sizeof(datatype) )
char *calloc(sizeof(datatype), num of elements)
calloc() is more efficient as memory is allocated in 1
cycle so fewer clock cycles, more faster executiop.
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / venkateswarlupanidapu
malloc occupies byte of space in memory location and holds
only one argument of data bytes.
calloc occupies and holds 2 bytes of memory in address
location with arguments databytes,number of data bytes.
calloc occupies in structure of blocks and malloc allocates
in struncture of databytes.
Is This Answer Correct ? | 14 Yes | 12 No |
Answer / rinky
malloc use boy as a male condom
calloc use girl as a Female condom
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / divya sharma
malloc takes the single argument nd calloc takes two argument
malloc initialize byte of memory while calloc initialize the
block of memory
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / md ajij
1.malloc() allocate one block of space in memory , argument
of the malloc is the size of the block.
where as calloc() allocate multiple blocks in the memory
,argument of the malloc() is the size of a block and number
of blocks.
2. malloc() takes garbage value at the initial time where
initial value of calloc() is zero.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / naresh guguloth(iiit,basar)b09
malloc():-
-------
It is used to allocate memory for one variable only.
int*hi=(int*)malloc(sizeof(int));
calloc():-
It is used to allocate memory for any array.
int*bye=(int*)calloc(sizeof(int),10)
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / bavithra
malloc() doesnot initialize the allocated memory
calloc() initializes the allocated memory to ZERO
Is This Answer Correct ? | 1 Yes | 1 No |
Write a program to print factorial of given number without using recursion?
What is else if ladder?
A marketing company wishes to construct a decision table to decide how to treat clients according to three characteristics: Gender, City Dweller, and age group: A (under 30), B (between 30 and 60), C (over 60). The company has four products (W, X, Y and Z) to test market. Product W will appeal to female city dwellers. Product X will appeal to young females. Product Y will appeal to Male middle aged shoppers who do not live in cities. Product Z will appeal to all but older females.
plz answer.. a program that takes a string e.g. "345" and returns integer 345
What is equivalent to ++i+++j?
how to execute with out main in cprogram
What are the different types of C instructions?
What does typeof return in c?
what is the value of b if a=5; b=++a + ++a
31 Answers Infosys, TCS, Tech Mahindra,
What are the 3 types of structures?
Write a C program to count the number of email on text
in linking some of os executables are linking name some of them