R15 Reverse array (in-place using recursion) Dry Run in C

R15 Reverse array (in-place using recursion) is an interactive C dry run visualizer from the Recursion 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.

R15 Reverse array (in-place using recursion) Program Code

#include <stdio.h>

void reverseArray(int arr[], int left, int right) {
    if(left >= right) return;
    int temp = arr[left];
    arr[left] = arr[right];
    arr[right] = temp;
    reverseArray(arr, left + 1, right - 1);
}

void printArray(int arr[], int n) {
    for(int i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");
}

int main() {
    int arr[] = {10, 20, 30, 40, 50, 60};
    int n = sizeof(arr) / sizeof(arr[0]);
    
    printf("Original: ");
    printArray(arr, n);
    
    reverseArray(arr, 0, n - 1);
    
    printf("Reversed: ");
    printArray(arr, n);
    return 0;
}

View the complete Recursion programs page.

Program Console R15 Reverse array (in-place using recursion) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.