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


I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int arr[5], i, sum = 0;
  7. int *ptr;
  8.  
  9. cout << "Enter any 5 numbers :";
  10. for (i = 0; i < 5; i++) {
  11. cin >> arr[i];
  12. }
  13.  
  14. ptr = arr;
  15. for (i = 0; i < 5; i++) {
  16. sum = sum + *(ptr + i);
  17. }
  18.  
  19. cout << "\nSum of array elements :" << sum;
  20.  
  21. return 0;
  22.  
  23. }
  24.  

Result

C++ language techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.