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);
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.
    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 .");
    puts(" failed Memory allocation.");

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

Post Your Answers

User Email:

User Name:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher