Q:

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

belongs to collection: C++ language Pointer Exercises

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter any 5 numbers :10

20

30

40

50

Sum of array elements :150

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C++ program to find length of string using p... >>
<< Write C++ program to add two numbers using pointer...