C Program to find sum of array elements using pointers


In this program, You will learn how to find sum of array elements using pointers in c.


sum = sum + *(ptr + i);


Example: How to find sum of array elements using pointers in c

Run it Now
#include<stdio.h>

int main() {

   int arr[5];
   int *ptr, i, sum = 0;

   printf("Enter Five Numbers :");
   for (i = 0; i < 5; i++) {
       scanf("%d", &arr[i]);
   }

   ptr = arr;
   for (i = 0; i < 5; i++) {
       sum = sum + *(ptr + i);
   }
   printf("\nThe Sum of All Numbers is :%d", sum);

   return 0;
}

Output:

Enter Five Numbers :5 10 15 20 25
The Sum of All Numbers is :75