Write a C program to create a dynamic array of integers using pointers.

 

#include<stdio.h>
main()
{
int *ptr,i,n;
clrscr();
printf("Input the size of an array:\n");
scanf("%d",&n);
ptr=(int*)malloc(n*sizeof(int));
printf("Input the array elements\n");
for(i=0;i<n;i++)
scanf("%d",(ptr+i));
printf("The array is \n");
for(i=0;i<n;i++)
printf("%d\t",*(ptr+i));
free(ptr);
getch();
}

 

 

Input the size of an array:
6
Input the array elements
55
66
99
22
33
20
The array is
55 66 99 22 33 20