- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sum of array using pointer arithmetic in C++
This is a C++ program to find out sum of array elements using pointer.
Algorithm
Begin Initialize the array elements with values from user input. Initialize s = 0 Loop for i = 0 to s = s + *(ptr + i) Print the sum value in variable s. End
Example Code
#include<iostream> using namespace std; int main() { int a[7], i, s = 0; int *ptr; cout << "Enter the Numbers: "; for (i = 0; i < 7; i++) { cin >> a[i]; } ptr = a; for (i = 0; i < 7; i++) { s = s + *(ptr + i); } cout << "\nSum of Elements of Array: " << s; }
Output
Enter the Numbers: 1 2 3 4 5 6 7 Sum of Elements of Array: 28
- Related Articles
- Sum of array using pointer arithmetic in C
- Pointer Arithmetic in C/C++
- Explain the concept of Array of Pointer and Pointer to Pointer in C programming
- C++ Program to Access Elements of an Array Using Pointer
- Pointer vs Array in C
- How to access elements of an array using pointer notation in C#?
- How to access array elements using a pointer in C#?
- How to sum two integers without using arithmetic operators in C/C++?
- C++ Program for sum of arithmetic series
- How to sum two integers without using arithmetic operators in C/C++ Program?
- Pointer to an Array in C
- Difference between pointer and array in C
- Double Pointer (Pointer to Pointer) in C
- Array Manipulation and Sum using C/C++
- C program to find the sum of arithmetic progression series

Advertisements