Find max/min element using pointer Dry Run in C

Find max/min element 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.

Find max/min element using pointer Program Code

#include <stdio.h>

void findMinMax(int *ptr, int n, int *min, int *max) {
    int i;
    *min = ptr[0];
    *max = ptr[0];
    
    for(i = 1; i < n; i++) {
        if(*(ptr + i) < *min) {
            *min = *(ptr + i);
        }
        if(*(ptr + i) > *max) {
            *max = *(ptr + i);
        }
    }
}

int main() {
    int i;
    int arr[] = {45, 23, 89, 12, 67, 34, 91, 56};
    int n = sizeof(arr)/sizeof(arr[0]);
    int min, max;
    
    findMinMax(arr, n, &min, &max);
    
    printf("Array elements: ");
    for(i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    printf("\nMinimum element: %d", min);
    printf("\nMaximum element: %d", max);
    
    return 0;
}

View the complete Pointersarrays programs page.

Program Console Find max/min element using pointer Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.