Solved programming problem

How to use calloc function with pointer in C.

Source code

#include <stdio.h>

int main()

{

    int n,i;

    printf("Please Enter The array Size: ");

    scanf("%d",&n);

    int *array = (int*)calloc(n,sizeof(int)); ///using calloc function to use only 'n' space for the array

    printf("Please Enter %d element of the array: ",n);

    for(i=0; i<n; i++)

    {

        scanf("%d",&array[i]);

    }

    printf("
The elements of the array:");

    for(i=0; i<n; i++)

    {

        printf("%d ",array[i]);

    }

    printf("
");

    return 0;

}

Output

Please Enter The array Size: 5
Please Enter 5 element of the array: 1 2 3 4  5

The elements of the array:1 2 3 4 5

Join the discussion

Add your comment