Program to input 'n' number in array and display it using pointer

1D (one dimensional) Array can be entered and displayed using pointer method also.

#include<stdio.h>
#include<conio.h>
void main ()
{ int a[100], i, *ptr, n;
ptr=a;
printf("Enter the numbr of elements");
scanf("%d",&n);
printf("Enter %d elements", n);
for (i=0; i<n; i++)
  scanf("%d", (ptr +i)]);
}

printf("\n The elements are:\n");
for (i=0; i< n; i++)
{
printf("%d", *(ptr+i));
}
getch();
}

Only difference in the pointer is array a[] is replaced by ptr (a pointer).
*ptr represents the content or value of the array.

Post a Comment

If you need anything to ask, Comment below:

Previous Post Next Post