Compare two arrays using pointer Dry Run in C

Compare two arrays using pointer is an interactive C dry run visualizer from the Pointersarrays 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.

Compare two arrays using pointer Program Code

#include <stdio.h>
int compareArrays(int *arr1, int *arr2, int n) {
    for(i = 0; i < n; i++) {
        if(*(arr1 + i) != *(arr2 + i)) {
            return 0;  // Not equal
        }
    }
    return 1;  // Equal
}

int compareArraysPtr(int *ptr1, int *ptr2, int n) {
    int *end = ptr1 + n;
    while(ptr1 < end) {
        if(*ptr1 != *ptr2) {
            return 0;
        }
        ptr1++;
        ptr2++;
    }
    return 1;
}

int main() {
    int arrA[] = {10, 20, 30, 40, 50};
    int arrB[] = {10, 20, 30, 40, 50};
    int arrC[] = {10, 20, 35, 40, 50};
    int n = sizeof(arrA)/sizeof(arrA[0]);
    
    printf("arrA vs arrB: %s\n", compareArrays(arrA, arrB, n) ? "EQUAL" : "NOT EQUAL");
    printf("arrA vs arrC: %s\n", compareArrays(arrA, arrC, n) ? "EQUAL" : "NOT EQUAL");
    
    printf("arrA vs arrB (ptr method): %s\n", compareArraysPtr(arrA, arrB, n) ? "EQUAL" : "NOT EQUAL");
    
    return 0;
}

View the complete Pointersarrays programs page.

Program Console Compare two arrays using pointer Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.