OOP with C++ Practical | Array: Sum of Array Elements Using Pointers | FYIT | Bansode Tech Solution

Опубликовано: 04 Май 2026
на канале: BANSODE TECH SOLUTION
22
0

OOP with C++ Practical | Array: Sum of Array Elements Using Pointers | FYIT | Bansode Tech Solution
   • OOP with C++ Practical | Array: Sum of Arr...  

Here’s a simple C++ program that uses pointers to compute the sum of all elements in an array 👇

✅ Program: Sum of Array Elements Using Pointers
#include iostream
using namespace std;

int main() {
int n;

cout "Enter the number of elements in the array: ";
cin n;

int arr[n];

cout "Enter " n " elements: ";
for (int i = 0; i lessthan n; i++) {
cin *(arr + i); // using pointer arithmetic

}

int sum = 0;
for (int i = 0; i less than n; i++) {
sum += *(arr + i); // access elements using pointer
}

cout "Sum of all elements = " sum endl;

delete[] arr; // free allocated memory
return 0;
}

💡 Explanation

int *arr = new int[n]; → dynamically creates an array of n integers.
*(arr + i) → accesses the i-th element of the array using a pointer.
The program then sums up all values and displays the total.
Finally, delete[] arr; frees the allocated memory.

🧮 Sample Output
Enter number of elements: 5
Enter 5 elements: 10 20 30 40 50
Sum of all elements = 150

🧠 Concept Recap
Concept Example Meaning
arr base address pointer to first element
arr + i address of element i pointer arithmetic
*(arr + i) value at that address element value

💡 Perfect for all IT, CS, and BCA students.

📘 Playlist Link:   • OOP with C++ Practical Playlists  

#Cpp #OOP #FYIT #CPlusPlus #Programming #BansodeTechSolution #ITPracticals


#Subscribe the Channel Link :- #bansodetechsolution #ajupgrading
https://www.youtube.com/c/AjUpgrading...

If you have any Queries or Doubts, DM me on Instagram:- #bansode_ajay_2102
https://www.instagram.com/bansode_aja...
@AjUpgradingBANSODETECHSOLUTION

LinkedIn Profile
  / aj-upgrading-bansode-tech-solution-0a99657a  

#bansodeTechSolutions
   • OOP with C++ Practical | Array: Sum of Arr...