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

JAC Board Computer || IIT 2025 || Introductory Information Technology || Class 10 || Practical Examination 2025

Marks Division HOE 30 Marks IT Application Report File 20 Marks Viva - Voce 10 Marks 1) Write an HTML code to generate a web p...