What is the difference between "calloc" and "malloc"?

Answers were Sorted based on User's Feedback

What is the difference between "calloc" and "malloc"?..

Answer / shweta

calloc initializes memory with 0 while malloc doesn't

Is This Answer Correct ?    25 Yes 4 No

What is the difference between "calloc" and "malloc"?..

Answer / ven

In addiion, calloc requires two parameters whereas ,malloc
only one

Is This Answer Correct ?    19 Yes 6 No

What is the difference between "calloc" and "malloc"?..

Answer / vijay

Calloc allocates the array of blocks of memory whearas
malloc allocates the memory of the size given as an

Is This Answer Correct ?    12 Yes 2 No

What is the difference between "calloc" and "malloc"?..

Answer / saugat biswas

Malloc allocates memory but does not initialize it.
Example: char *szPtr = ( char* ) malloc( sizeof( char ) *
100 );
Here szPtr is assigned 100 bytes. But the memory is not
initialized. It contains garbage.

Allocates a block of memory for an array of 'n' elements,
each of them 'l' bytes long, and initializes all its bits
to zero.
Example: char *szPtr = ( char* ) calloc( 100, sizeof(
char ));
Here szPtr is assigned 100 bytes & the memory is
initialized to 0.

Is This Answer Correct ?    11 Yes 2 No

What is the difference between "calloc" and "malloc"?..

Answer / gallanticscorp

calloc means alloting memory dynamically
malloc means alloting memory at first and it is fixed

Is This Answer Correct ?    5 Yes 3 No

What is the difference between "calloc" and "malloc"?..

Answer / subhrajit

mallco is used in c language for static memory location in
heap area and i donot no the calloc.

Is This Answer Correct ?    1 Yes 0 No

What is the difference between "calloc" and "malloc"?..

Answer / samveethsingh

malloc create the single block of given size by user
calloc creates multiple blocks of given size

Is This Answer Correct ?    0 Yes 0 No

What is the difference between "calloc" and "malloc"?..

Answer / edwin

malloc - create the memory space

calloc-calculate the memory space

Is This Answer Correct ?    0 Yes 4 No

What is the difference between "calloc" and "malloc"?..

Answer / srikanth


Is This Answer Correct ?    3 Yes 27 No

Post New Answer

More C++ General Interview Questions

Difference between Operator overloading and Functional overloading?

10 Answers   HP,

i want the NIC programmer-B model papaer pattren, iwant the all model papers?

15 Answers   NIC,

Is there any difference between dlearations int* x and int *x? If so tell me the difference?

16 Answers   Lason,

Implement strcmp

3 Answers   Citadel, Bloomberg,

write a C++ programming using for loop: * * * * * * * * * *

4 Answers   TCS,

in C++ , the word plus plus who found this?

4 Answers  

class X { private: int a; protected: X(){cout<<"X constructor was called"<<endl;} ~X(){cout<<"X destructor was called"<<endl} }; Referring to the code above, which one of the following statements regarding "X" is TRUE? a) X is an abstract class. b) Only subclasses of X may create X objects. c) Instances of X cannot be created. d) X objects can only be created using the default copy constructor. e) Only friends can create instances of X objects.

2 Answers   Quark,

let a,b,c be three integer numbers.write a c++ program with a function void rotate 1()such that a->b->c and c->a.

1 Answers  

Write a program to calculate the following i want a c++program for this condition 1+4+9+16+….+100 Like this (1^2+2^2) Hint use function pow(a,b)

4 Answers   TCS, HTC,

class Alpha { public: char data[10000]; Alpha(); ~Alpha(); }; class Beta { public: Beta() { n = 0; } void FillData(Alpha a); private: int n; }; How do you make the above sample code more efficient? a) If possible, make the constructor for Beta private to reduce the overhead of public constructors. b) Change the return type in FillData to int to negate the implicit return conversion from "int" to "void". c) Make the destructor for Alpha virtual. d) Make the constructor for Alpha virtual. e) Pass a const reference to Alpha in FillData

2 Answers   Quark,

Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

0 Answers  

How Virtual functions call up is maintained?

2 Answers