Tech Study

C++ Program to Find Sum of Array Elements

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

Here are some more C++ program for your practice :

Write C++ program to print sum of digits enter by user

How To Concatenate Two Strings In C++ Using Pointers

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

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more