Use calloc() allocate memory - C Memory

C examples for Memory:calloc

Description

Use calloc() allocate memory

Demo Code

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
    unsigned long num;
    int *ptr;//from   w  w w.j  a  v  a2 s.c o m

    printf("Enter the number of type int to allocate: ");
    scanf("%ld", &num);

    ptr = (int*)calloc(num, sizeof(long long));

    if (ptr != NULL)
        puts("Memory allocation was successful.");
    else
        puts("Memory allocation failed.");
    return 0;
}

Result


Related Tutorials