Pointer Program #1

10. Read n numbers in an array and print them using pointer.

#include<stdio.h>
void main ()
{
     int n,i,*p,array[100];
     p=array;
     printf("Enter size of array:\n");
     scanf("%d",&n);
     printf("Enter elements of array:\n");
     for(i=0;i<n;i++)
     {
          scanf("%d",p+i);
     }
     printf("The array using pointer is:\n");
     for(i=0;i<n;i++)
     {
          printf("%d\n",*(p+i));
     }
}

Output

  • Enter size of array:
    5
    Enter elements of array:
    12
    13
    14
    15
    16
    The array using pointer is:
    12
    13
    14
    15
    16

Note:

The above method uses array notation to print elements.

You can also use pointer notation to access an array in C.

The statement array[i] is equivalent to *(array + i).

For download this program please check the link ➡➡ Download


Comments

Popular

Basic Program #3

Array Program #4

Singly Linked List program #1

Basic program #2