Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

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 <stdlib.h>
#include <stdio.h>
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);
}
  
Posted By: Name:Rajesh Kr URL: What is the use of calloc() function?