1.

What Do You Mean By Dynamic Memory Allocation? Give An Example.

Answer»

The process of allocating memory at the time of execution is called dynamic memory allocation. The allocation and release of this memory space can be done with the help of some built in functions whose prototypes are FOUND in alloc.h and stdlib.h.
Example:-
#include<stdio.h>
#include<alloc.h>
main()
{
int *p, N, i;
printf( “Enter the number of integers to be entered.”);
scanf(“%d”, &n);
p=(int *)malloc(n*sizeof(int));
if(p==NULL)
{
printf(“Memory not AVAILABLE”);
EXIT(1);
}
for(i=0;i<n;i++)
{
printf(“Enter an integer”);
scanf(“%d”, p+1);
}
for(i=0;i<n;i++)
printf(“%d”, *(p+i));
}
RETURN 0;
}

 

The process of allocating memory at the time of execution is called dynamic memory allocation. The allocation and release of this memory space can be done with the help of some built in functions whose prototypes are found in alloc.h and stdlib.h.
Example:-
#include<stdio.h>
#include<alloc.h>
main()
{
int *p, n, i;
printf( “Enter the number of integers to be entered.”);
scanf(“%d”, &n);
p=(int *)malloc(n*sizeof(int));
if(p==NULL)
{
printf(“Memory not available”);
exit(1);
}
for(i=0;i<n;i++)
{
printf(“Enter an integer”);
scanf(“%d”, p+1);
}
for(i=0;i<n;i++)
printf(“%d”, *(p+i));
}
return 0;
}

 



Discussion

No Comment Found