Malloc
Malloc is a subroutine for performing dynamic memory allocation in the C and C++ programming languages.
/*
http://www.ProbCOMP.com
Malloc is a subroutine for performing dynamic memory allocation in the C and C++ programming languages.
It is part of the standard library for both languages.Programs must properly manage dynamic memory allocated
through the use of malloc to avoid memory leaks and memory corruption
*/
#include<stdio.h>
#include<stdlib.h>
// malloc is used for dynamic memory allocation
void main()
{
int *p,n,i;
printf("enter the size of an array: ");
scanf("%d",&n);
p=(int *)malloc(sizeof(int)*n);
printf("\nenter the values of the array :");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("\nYOU ENTERED\n");
for(i=0;i<n;i++)
printf("%d ",p[i]);
}
Download Program


