Originally Posted by
G4143
calloc zeros the memory it allocates.
From my manpages:
Thank you,
program proves how calloc is different then malloc
Code:
#include<stdio.h>
#include<stdlib.h>
int main (void)
{
// memory is allocated for one integer variables using malloc
int *x = malloc(1 * sizeof(int));
// memory is allocated for one integer variables using calloc
int *y = calloc(1, sizeof(int));
if ( x != NULL)// Check if the memory has been successfully
{
printf("Memory successfully allocated using malloc.\n");
printf( "x = %d\n", *x);
}
if ( y != NULL)// Check if the memory has been successfully
{
printf("Memory successfully allocated using calloc.\n");
printf( "y = %d\n", *y);
}
return 0;
}
Memory successfully allocated using malloc.
x = 134472
Memory successfully allocated using calloc.
y = 0