Skip to main content

Sum of Array Elements Using Pointers in C

1 min read Updated June 30, 2026
Share:
On this page (6sections)

About this page

This program sums a pre-initialized array using pointer arithmetic (pt++). The array values are fixed in code — no user input.

For the version that reads values from the keyboard with scanf and pointer indexing, see Read, Print and Sum using pointers.

Syntax

pointer_variable = &var[position];

pointer_variable++ is increasing Address value based on Data Type
pt++; --> Its location next position of Array

Simple Program for Sum of Integer an array using pointers

/* Simple Program for Sum of Integer in an array using pointers in C*/
/* Pointer and Array Program,C Pointer Examples */

#include <stdio.h>

#define MAX_SIZE 5

int main() {

  int var[] = {10, 20, 30, 40, 50};
  int i = 0, sum = 0;

  //Pointer Variable Declaration for Integer Data Type 
  int *pt;

  //& takes the address of var , Here now pt == &var, so *pt == var
  pt = &var[0];

  while (i < MAX_SIZE) {
    i++;

    // Calculate sum using pointer
    sum = sum + *pt;

    // pt++ is increasing Address value based on Data Type
    pt++;
  }

  printf("Sum of Array : %d", sum);

  return 0;
}

Sample Output

Sum of Array : 150

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C program do?
It is a C example program that demonstrates Sum of Array Elements Using Pointers, including the complete source code and the expected sample output.
How do I compile and run this C program?
Save the code in a `.c` file, compile it with `gcc filename.c -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses loops to iterate over data and arrays, illustrating a common pattern in C programming.

Related Tutorials

Search tutorials