Insert a substring at a given position Dry Run in C

Insert a substring at a given position is an interactive C dry run visualizer from the String Functions 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.

Insert a substring at a given position Program Code

#include <stdio.h>
#include <string.h>

int main() {
    char str[100] = "Hello World";
    char substr[] = "Beautiful ";
    int pos = 6;
    
    printf("Original: %s\n", str);
    
    int len_str = strlen(str);
    int len_sub = strlen(substr);
    
    // Shift characters to the right
    for(int i = len_str; i >= pos; i--) {
        str[i + len_sub] = str[i];
    }
    
    // Insert substring
    for(int i = 0; i < len_sub; i++) {
        str[pos + i] = substr[i];
    }
    
    printf("After insertion: %s\n", str);
    return 0;
}

View the complete String Functions programs page.

Program Console Insert a substring at a given position Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.