

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between malloc and calloc
In this post, we will understand the difference between malloc and calloc.
Malloc
The method ‘malloc’ is used to assign a block of memory when it is requested.
It doesn’t clear the memory.
It only initializes the allocated memory when explicitly requested.
It allocates memory of a specific ‘size’.
This size is passed as parameter to it.
This size is allocated from a heap.
It performs its job quickly.
Example
void *malloc(size_t size);
Calloc
It assigns the requested memory to multiple blocks.
This memory allocated is initiated to zero.
This initialization to 0 is done by ‘calloc’ method.
It allocates memory to the required operation of a specific ‘size’, i.e num * size.
The ‘num’ refers to number of blocks of memory.
It is slow in comparison to ‘malloc’ method.
Example
void *calloc(size_t num, size_t size);
- Related Questions & Answers
- calloc() versus malloc() in C
- Difference between new and malloc( )
- What is the difference between new/delete and malloc/ free in C/ C++?
- What is Calloc in C language?
- How do malloc() and free() work in C/C++?
- Difference between C# and .Net
- Difference between Process and Thread
- Difference between Concurrency and Parallelism
- Difference between localhost and 127.0.0.1?
- Difference between JCoClient and JCoDestination
- Difference between String and StringBuffer.
- Difference between StringBuffer and StringBuilder.
- Difference between CPU and GPU
- Difference between TDM and FDM
- Difference between CRT and LCD
Advertisements