use of malloc() function ....
#include<stdio.h>
#include<conio.h>
int main()
{
int *ptr,n,i;
printf("Enter the number of elements : ");
scanf("%d",&n);
ptr=(int *)malloc(n*sizeof(int));
printf("Enter the elements : ");
for(i=0;i<n;i++)
scanf("%d",(ptr+i));
printf("Elements are : ");
for(i=0;i<n;i++)
printf("%d",*(ptr+i));
system("pause");
}
#include<conio.h>
int main()
{
int *ptr,n,i;
printf("Enter the number of elements : ");
scanf("%d",&n);
ptr=(int *)malloc(n*sizeof(int));
printf("Enter the elements : ");
for(i=0;i<n;i++)
scanf("%d",(ptr+i));
printf("Elements are : ");
for(i=0;i<n;i++)
printf("%d",*(ptr+i));
system("pause");
}
input:
Enter the number of elements : 4
Enter the elements : 2 3 4
ouput :
Elements are : 2 3 4
Comments
Post a Comment