What is the use of calloc() function?

What is the use of calloc() function?

Calloc() function is used to initialize memory. Calloc() function is used to allocates a group of object.
Syntax of allocating Calloc() function are given below:
void *calloc(size_t number, size_t size);
Where,
size_t-> is a synonym for unsigned.
number-> is the num of object to allocate.
size-> It shows the size of each object in bytes.
  When memory allocation with calloc() function is successful,than function returns a pointer.
Otherwise,it returns 0.
Example:
#include 
#include 
main()
{   
    unsigned number;
    int *pointer;
    printf("Enter the num(int)to allocate: ");
    scanf("%d", &number);
    pointer = (int*)calloc(number, sizeof(int));
    if (pointer != NULL)
    puts("successful Memory allocation .");
    else
    puts(" failed Memory allocation.");
    return(0);
}
  

By:Vivek Kr. Agarwal
Date:2007-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher