Reverse string using pointer Dry Run in C

Reverse string 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.

Reverse string using pointer Program Code

#include <stdio.h>
void reverseString(char *str) {
    char *start = str;
    char *end = str;
    char temp;
    
    // Move end to the last character (before '\0')
    while(*end != '\0') {
        end++;
    }
    end--;  // Point to last character
    
    // Swap characters from both ends
    while(start < end) {
        temp = *start;
        *start = *end;
        *end = temp;
        start++;
        end--;
    }
}

int main() {
    char str1[] = "Hello";
    char str2[] = "Programming";
    char str3[] = "C";
    char str4[] = "123456789";
    
    printf("Original: \"%s\"\n", str1);
    reverseString(str1);
    printf("Reversed: \"%s\"\n\n", str1);
    
    printf("Original: \"%s\"\n", str2);
    reverseString(str2);
    printf("Reversed: \"%s\"\n\n", str2);
    
    printf("Original: \"%s\"\n", str3);
    reverseString(str3);
    printf("Reversed: \"%s\"\n\n", str3);
    
    printf("Original: \"%s\"\n", str4);
    reverseString(str4);
    printf("Reversed: \"%s\"\n", str4);
    
    return 0;
}

View the complete Pointersarrays programs page.

Program Console Reverse string using pointer Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.