C Program For Memory Allocation With Calloc And Free





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

void main(){

int* ptr;

int n,i;


system("cls");
printf("\n\t\tProgram Of Calloc With Free ");

printf("\n\t\tEnter Number of Elements : ");
scanf("%d",&n);

ptr=(int*) calloc(n,sizeof(int));

if(ptr==NULL){
printf("\n\t\tMemory Not Allocated ");
exit(0);
}else{
printf("\n\t\tMemory Is Allocated");

printf("\n\t\tGetting elements.....");
for (i=0;i<n;i++){
printf("\n\t\t%d : ",i+1);
scanf("%d",&ptr[i]);
}
printf("\n\t\tPrinting Elements\n");

for(i=0;i<n;i++){
printf("\n\t\t%d",ptr[i]);
}

}

free(ptr);
printf("\n\n\t\tMemory Free In Calloc\n");

getch();
}


//Output:


Comments

Post a Comment

Popular posts from this blog

HTML Signup Login Form With Source Code