Write a C Program using pointers to read an array of integers
#Write a C Program using pointers read an array of integers
Point to be remember :
The array's size (n) must be entered by the user.It declares an array of integers (arr) of size n.Next, the programme inserts integers into the array using pointers.
In the end, pointers are used to display the entered array.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr,i,n;
clrscr();
printf("Enter the no of elements:");
scanf("%d",&n);
ptr=(int *)malloc(sizeof(int)*n);
if(ptr==NULL)
{
printf("Not enough memory");
exit(1);
}
for(i=0; i<n; i++)
{
printf("Enter %d element : ",i+1);
scanf("%d",&ptr[i]);
}
getch();
return 0;
}