Tuesday, September 23, 2014

REALLOC EXMAPLE IN C PROGRAMMING LANGUGAE

#include <stdio.h>
#include <stdlib.h>
void main()
{
    int *ptr,*rptr,i,n1,n2;
    clrscr();
    printf("Enter size of array: ");
    scanf("%d",&n1);
    ptr=(int*)malloc(n1*sizeof(int));
    printf("\nAddress of previously allocated memory: ");
    for(i=0;i<n1;++i)
    {
printf("%u\t  ",ptr+i);
    }
    printf("\nEnter new size of array: ");
    scanf("%d",&n2);
    rptr=realloc(ptr,n2);
     for(i=0;i<n2;++i)
     {
printf("%u\t  ",rptr+i);
     }
    getch();
}

No comments:

Post a Comment

12th January Swami Vivekanand Jayanti: National Youth Days

The day serves as a reminder to the youth of India to remain steadfast in their goals and contribute positively to society. Swami Vivekanand...