C program to find sum of array elements using pointers || Pointers || C Programming
In this, we are going to find sum of an array by using Pointers in C Programming Language.

 

#include <stdio.h>
int main()
{
    int x[5];
    int i = 0, sum = 0;
    int *ptr;
    ptr = x; //pointer stores address of an array
    printf("Input 5 elements:\n");

    //inputting elements of an array
    for (i = 0; i < 5; i++)
    {
        scanf("%d", x + i);
    }

    for (i = 0; i < 5; i++) //sum of elements of an array using pointer
    {
        sum = sum + *ptr;
        ptr++;
    }
    printf("Sum of elements of array:%d", sum);
    return 0;
}

//..........Coded by Ananya Maurya

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post