Write C++ program to Sum of Array Elements using Pointers

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.

#include <iostream>
using namespace std;
 
int main() {
 
   int arr[5], i, sum = 0;
    int *ptr;
 
    cout << "Enter any 5 numbers :";
    for (i = 0; i < 5; i++) {
        cin >> arr[i];
    }
 
    ptr = arr;
    for (i = 0; i < 5; i++) {
        sum = sum + *(ptr + i);
    }
 
    cout << "\nSum of array elements :" << sum;
 
    return 0;
 
}

Result

Write C++ program to Sum of Array Elements using Pointers
Write C++ program to Sum of Array Elements using Pointers

3 thoughts on “Write C++ program to Sum of Array Elements using Pointers”

Leave a Comment