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;
}
I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
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