Thursday, 18 October 2012

Program Of Array Using Realloc In C

#include<stdio.h>
#include<conio.h>
 
main()
 
{
 
int *a,i,n,y;
 
clrscr();
 
printf("How many Blocks U want to Create For Array =");
 
scanf("%d",&n);
 
for(i=0;i<n;i++)
{
 
}
 
for(i=0;i<n;i++)
 
{
 
printf("a[%d]==> ",i);
 
scanf("%d",&a[i]);
 
}
 
printf("\n============Array Is=============\n");
 
for(i=0;i<n;i++)
 
{
 
printf("\n a[%d]==>%d ",i,a[i]);
 
}
 
printf("\n How Many Memory U want to Reallocate =");
 
scanf("%d",&y);


for(i=0;i<y;i++)
{
 
}
 
for(i=n;i<n+y;i++)
 
{
 
printf("a[%d]==> ",i);
 
scanf("%d",&a[i]);
 
}
 
printf("\n======== again Array Is=============\n");
 
for(i=0;i<n+y;i++)
 
{
 
printf("\n a[%d]==>%d ",i,a[i]);
 
}
 
getch();
 
}

-------------------------------------------------------------------------------

What is Realloc ?


The Realloc() function changes the size of a block of memory that was previously allocated with Malloc() or Calloc().

No comments:

Post a Comment