Pointer comparison Dry Run in C

Pointer comparison 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.

Pointer comparison Program Code

#include <stdio.h>
int main() {
    int arr[] = {10, 20, 30, 40, 50};
    int *p1 = arr;       // points to arr[0]
    int *p2 = arr + 2;   // points to arr[2]
    int *p3 = arr + 4;   // points to arr[4]
    
    printf("p1 points to: %d\n", *p1);
    printf("p2 points to: %d\n", *p2);
    printf("p3 points to: %d\n", *p3);
    
    printf("\nComparisons:\n");
    printf("p1 == p2? %s\n", (p1 == p2) ? "true" : "false");
    printf("p1 < p2? %s\n", (p1 < p2) ? "true" : "false");
    printf("p2 > p1? %s\n", (p2 > p1) ? "true" : "false");
    printf("p2 <= p3? %s\n", (p2 <= p3) ? "true" : "false");
    
    // Difference between pointers
    printf("\nPointer difference:\n");
    printf("p3 - p1 = %ld (elements apart)\n", p3 - p1);
    printf("p2 - p1 = %ld\n", p2 - p1);
    
    return 0;
}

View the complete Pointersintro programs page.

Program Console Pointer comparison Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.