WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c
file management?

Answers were Sorted based on User's Feedback



WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / chris_sreekanth

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 ?    268 Yes 63 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / ananth kumar

malloc
Holds 1 argument data type
allocates memory byte equivalent to data type
not init alloted memory

Calloc
Holds 2 arguments, data type and number of datas (n)
allocates memory block equivalent to n * data type
clears alloted memory with 0

Is This Answer Correct ?    173 Yes 39 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / shruti

malloc will only allocate space in the memory..

calloc will allocate space in the memory as well as
initialise it to a particular value.

Is This Answer Correct ?    134 Yes 39 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / prakashdasari

malloc () for allocating the single block of memory
calloc () for allocating multiple blocks of memory
the values assigned are garbage in case of malloc() and
proper values (zeros) are assigned in case of calloc().

Is This Answer Correct ?    114 Yes 34 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / abhishek pathak mnnit

1- malloc() takes one argument while calloc takes 2 argument.
2- default value of malloc is garvage while calloc is 0;
3- malloc allocate memory in contiguous form while calloc
allocate memory in contiguous form if not avilable the takes
diffrent place.

Is This Answer Correct ?    88 Yes 18 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / arshad

1.
calloc function takes two argument while malloc takes only 1
2.
by default memory allocated by malloc contains garbage values
whereas that allocated by calloc contains all zero.

Is This Answer Correct ?    49 Yes 15 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / vini sharma

malloc()
allocates byte of memory and calloc() allocates block of
memory.

Is This Answer Correct ?    50 Yes 22 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / ragu

All the above are true

Is This Answer Correct ?    58 Yes 33 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / madan gopal singh

malloc() is a one argument function while calloc() is two
argument function
malloc() take garbage value at initial time while calloc()
take null values at initial time

Is This Answer Correct ?    27 Yes 13 No

WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management? ..

Answer / smitha

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.

Is This Answer Correct ?    17 Yes 3 No

Post New Answer

More C Interview Questions

What is a method in c?

0 Answers  


What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }

0 Answers   Google,


What is the scope of static variables in c language?

0 Answers  


What is the difference between char array and char pointer?

0 Answers  


how should functions be apportioned among source files?

0 Answers  






What is difference between arrays and pointers?

0 Answers  


What library is sizeof in c?

0 Answers  


What is calloc malloc realloc in c?

0 Answers  


Give the rules for variable declaration?

0 Answers  


What are pointers?

0 Answers   Accenture, Tavant Technologies, Zensar,


What is difference between constant pointer and constant variable?

0 Answers   Hexaware,


study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above

15 Answers   Accenture, TCS,


Categories