realloc( ) statement:
Code:
#include<stdio.h>
#include<stdlib.h>
void main()
{
int n,*p,i,*q;
printf("Enter the size of elements:\n");
scanf("%d",&n);
p=(int*)malloc(n);
printf("Enter the elements:\n");
for(i=0;i<n;i++)
scanf("%d",p+i);
printf("The elements are:\n");
for(i=0;i<n;i++)
printf("%d\t",*(p+i));
printf("\nEnter the new size:\n");
scanf("%d",&n);
q=realloc(p,n);
printf("Enter the new elements:\n");
for(i=0;i<n;i++)
scanf("%d",q+i);
for(i=0;i<n;i++)
printf("%d\t",*(q+i));
}
Output:
Comment for your feedback!
Comments
Post a Comment
Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)