Calloc Function in C


The C library memory allocation function void *calloc(size_t nitems, size_t size) allocates the requested memory and returns a pointer to it.

The difference in malloc and calloc is that malloc does not set the memory to zero, whereas, calloc sets the allocated memory to zero.

Source Code

//calloc in Pointers
#include<stdio.h>
#include<stdlib.h>
int main()
{
    //void* calloc(size_t n,size_t size)
 
    int i,n;
    printf("\nEnter The Limit : ");
    scanf("%d",&n);
    int *ptr=(int *)calloc(n,sizeof(int));
 
    if(ptr==NULL)
    {
        printf("Memory Not Available ...");
        exit(1);
    }
 
    for(i=0; i<n; i++)
    {
        printf("Enter a integer : ");
        scanf("%d",ptr+i);
    }
 
    for(i=0; i<n; i++)
    {
        printf("\n%d :  %d  ",&ptr+i,*(ptr+i));
    }
 
    return 0;
}
 
 
 
 
To download raw file Click Here

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes