My Profile

I, Das ShrikKrishna J. MCA III IMSCD&R, Ahmednagar.

Monday, 15 August 2011

Implement calloc and realloc function

Write a Program in C to Implement "calloc" and "realloc" function
#include<stdio.h>
#include<conio.h>
void main()
{
int le,i,*pa,new_le;
clrscr();
printf("Enter Total Numbers\n");
scanf("%d",&le);
pa=(int*)calloc(le*sizeof(int));
printf("\nEnter %d numbers\n",le);
for(i=0;i<=le-1;i++)
{
scanf("%d",(pa+i));
}
printf("\nPrinting Numbers\n");
for(i=0;i<=le-1;i++)
{
printf("%d at %u\n",*(pa+i),(pa+i));
}
new_le=12;
pa=(int*)realloc(pa,new_le);
printf("\n\nAfter reallocating\n\n");
for(i=0;i<=new_le-1;i++)
{
printf("%d at %u\n",*(pa+i),(pa+i));
}
getch();
}

No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls