Pointers
Sum of Array Using Pointer
Traverse an array using pointer arithmetic and find the sum.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Traverse an array using pointer arithmetic and find the sum.
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
int *p = arr;
int sum = 0, n = 5;
for (int i = 0; i < n; i++) sum += *(p + i);
printf("Sum = %d\n", sum);
return 0;
}
Sum = 15