Sum of array using pointer arithmetic Last Updated : 21 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an array, write a program to find the sum of array using pointers arithmetic. In this program we make use of * operator . The * (asterisk) operator denotes the value of variable. The * operator at the time of declaration denotes that this is a pointer, otherwise it denotes the value of the memory location pointed by the pointer . sum() function is used to find the sum of the array through pointers. Examples : Input : array = 2, 4, -6, 5, 8, -1Output : sum = 12 Input : array = 1, 4, -6, 8, -10, -12Output : sum = -15 CPP // CPP program to find sum of array using pointers #include <iostream> using namespace std; // Function to find the sum of the array void sum(int* array, int length) { int i, sum_of_array = 0; for (i = 0; i < length; i++) sum_of_array = sum_of_array + *(array + i); cout << "sum of array is = " << sum_of_array; } // Driver function int main() { // Array to hold the values int array[] = { 2, 4, -6, 5, 8, -1 }; sum(array, 6); return 0; } Outputsum of array is = 12 Time Complexity: O(N)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Sum of array using pointer arithmetic M mohitw16 Follow Improve Article Tags : C++ pointer cpp-pointer Practice Tags : CPP Similar Reads C++ Pointer Arithmetic In C++, pointer arithmetic means performing arithmetic operations on pointers. It refers to the operations that are valid to perform on pointers. Following are the arithmetic operations valid on pointers in C++:Table of ContentIncrementing and Decrementing Pointer in C++Addition of Constant to Point 7 min read How to sum two integers without using arithmetic operators in C/C++? Given two integers a and b, how can we evaluate the sum a + b without using operators such as +, -, ++, --, ...? Method 1 (Using pointers)An interesting way would be: CPP // May not work with C++ compilers and // may produce warnings in C. // Returns sum of 'a' and 'b' int sum(int a, int b) { char * 4 min read Pointer to an Array in C++ Pointers in C++ are variables that store the address of another variable while arrays are the data structure that stores the data in contiguous memory locations. In C++, we can manipulate arrays by using pointers to them. These kinds of pointers that point to the arrays are called array pointers or 6 min read Pointer to an Array | Array Pointer A pointer to an array is a pointer that points to the whole array instead of the first element of the array. It considers the whole array as a single unit instead of it being a collection of given elements.Example:C #include<stdio.h> int main() { int arr[5] = { 1, 2, 3, 4, 5 }; int *ptr = arr; 5 min read A C/C++ Pointer Puzzle Prerequisite: Pointers Assuming the size of int = 4 bytes, size of a pointer variable = 8 byte, what will be the output of following program. Few hints on how to solve it: Size of int = 4 bytes, size of a pointer variable = 8 bytes (on my machine), adding 1 to a pointer makes the pointer point to it 2 min read Like