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.

void main ()
{ int a[100], i, *ptr, n;
printf("Enter the numbr of elements");
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));

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