C Program For malloc() and calloc() Function

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

//Diffrence between malloc and calloc function for Dynamic memory
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
   int *ar,n,i;
   printf("%d",sizeof(int));

   printf("Enter the limit");
   scanf("%d",&n);
   ar= (int*)calloc(sizeof(int),n); // n block of 4 size
   printf("Enter elements in array");
   for(i=0;i<n;i++)
   scanf("%d",&ar[i]);
for(i=0;i<n;i++)
   printf("%d",&ar[i]);

   free(ar);
}

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *