Pointer to an Array in C

Pointer to an Array in C
#include<stdio.h>

main()
{

int a[5],i,sum=0;
   int *p;
 
  printf("Enter array elements:");
 
   for(i=0;i<5;i++)
    {

       scanf("%d",&a[i]);   //user provide input

    }

     p=&a[0];   //you also assign base address to pointer as p=a
 
     for(i=0;i<5;i++)
      {

        sum=sum+*p;
        p++;          //increament in pointer address..point next address value in array

      }
     
       printf("Sum is:%d\n",sum);

}

Related Posts