Skip to content
Home » C Program to Read and write an array using the pointer

C Program to Read and write an array using the pointer

Learn about C Program to Read and write an array using the pointer in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C Program to Read and write an array using the pointer

Array can be accessed with index of the array and its name . 0th index of any array refers to base address of the array and hence the pointer to that 0th index can access whole array. here we develop c code using pointers.

#include<stdio.h>
int main()
{
   int x[5], i;
   int *pa;
   pa = &x[0]; // or, pa = &x;
   printf("Enter array element: ");
   for(i=0;i<5;i++)
   {
     scanf("%d", (pa+i)); 
   }
   printf("Elements in Array: ");
   for(i=0;i<5;i++)
   {
     printf("%d\t",*(pa+i));
   }
   printf("\n");
   return 0;
}

Output:

Enter array element: 34
56
76
31
43
Elements in Array: 34 56 76 31 43

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program to swap Numbers in Cyclic Order using Pointer
C Program to find Character is vowel or consonant using Pointer