C Program to Find Sum of Elements Stored in Given Array Using Pointers

In this program, you will learn to find sum of all elements stored in an array using pointers.



Source Code
#include<stdio.h>
#include<conio.h>
void main()
{
    int *ptr, arr[5], sum = 0, i;
    //clrscr();
    printf("Enter array elements: ");
    for(i=0; i<5 ; i++)
    {
        scanf("%d", &arr[i]);
    }
    ptr = arr;
    for(i=0; i<5; i++)
    {
        sum = sum + *ptr;
        ptr++;
    }
    printf("Sum of all array elements is : %d", sum);
    getch();
}
Output
Enter array elements: 42 75 63 85 49
Sum of all array elements is : 314





"Coding Hub - Learn to code" app now available on Google Play Store