Skip to main content

Simple Program for Pointer and Array Example in C

3 min read Updated June 30, 2026
Share:
On this page (9sections)

About this program

This is an example program in c pointer example programs. Read the concept first: C Pointers, then study the code and output below.

Overview

  • Array Pointer Assignment : pointer_variable = &var[position];
  • pointer_variable++ is increasing Address value based on Data Type
  • pt++; —> Its locate next position of Array

for example,

Array Pointer Assignment
pt = &var[0];
pt++;
now pt++ points var[1] of address.

Syntax

Array Pointer Assignment
pointer_variable = &var[position];

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

Simple Program for Pointer and Array Example

/* Simple Program for Pointer and Array Example 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;

  //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) {
    printf("Position : %d # Actual  : Value : %d , Address = %p \n", i, var[i], &var[i]);
    printf("Position : %d # Pointer : Value : %d , Address = %p \n\n", i, *pt, pt);
    i++;

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

  return 0;
}

Sample Output

Position : 0 # Actual  : Value : 10 , Address = 0060FEF4
Position : 0 # Pointer : Value : 10 , Address = 0060FEF4

Position : 1 # Actual  : Value : 20 , Address = 0060FEF8
Position : 1 # Pointer : Value : 20 , Address = 0060FEF8

Position : 2 # Actual  : Value : 30 , Address = 0060FEFC
Position : 2 # Pointer : Value : 30 , Address = 0060FEFC

Position : 3 # Actual  : Value : 40 , Address = 0060FF00
Position : 3 # Pointer : Value : 40 , Address = 0060FF00

Position : 4 # Actual  : Value : 50 , Address = 0060FF04
Position : 4 # Pointer : Value : 50 , Address = 0060FF04

How It Works

This C program demonstrates Simple Program for Pointer and Array. It first prepares the data it needs, then walks through the data with a loop to compute the result, and finally prints the output shown in the Sample Output above.

  1. Declare the variables that hold the program’s data.
  2. Iterate over the data using a loop to apply the logic.
  3. Print the final result to the console so you can compare it with the sample output.

Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.

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 Simple Program for Pointer and Array, 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