Access array using pointer arithmetic Dry Run in C

Access array using pointer arithmetic is an interactive C dry run visualizer from the Pointersintro programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Access array using pointer arithmetic Program Code

#include <stdio.h>
int main() {
    int arr[] = {10, 20, 30, 40, 50};
    int *ptr = arr;  // ptr points to arr[0]
    
    printf("Using array indexing:\n");
    for(int i = 0; i < 5; i++) {
        printf("arr[%d] = %d\n", i, arr[i]);
    }
    
    printf("\nUsing pointer arithmetic:\n");
    for(int i = 0; i < 5; i++) {
        printf("*(ptr + %d) = %d\n", i, *(ptr + i));
    }
    
    printf("\nUsing pointer increment:\n");
    ptr = arr;
    for(int i = 0; i < 5; i++) {
        printf("*ptr = %d, ", *ptr);
        ptr++;
    }
    
    return 0;
}

View the complete Pointersintro programs page.

Program Console Access array using pointer arithmetic Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.