Concatenate strings using pointer Dry Run in C

Concatenate strings 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.

Concatenate strings using pointer Program Code

#include <stdio.h>
void stringConcat(char *dest, char *src) {
    // Move dest to the end (to '\0')
    while(*dest != '\0') {
        dest++;
    }
    // Copy src to the end of dest
    while(*src != '\0') {
        *dest = *src;
        dest++;
        src++;
    }
    *dest = '\0';
}

void stringConcatCompact(char *dest, char *src) {
    while(*dest) dest++;      // Go to end
    while(*dest++ = *src++);  // Copy including null
}

int main() {
    char str1[100] = "Hello, ";
    char str2[] = "World!";
    char str3[100] = "Programming ";
    char str4[] = "in C";
    
    printf("Before concat: \"%s\"\n", str1);
    stringConcat(str1, str2);
    printf("After concat: \"%s\"\n", str1);
    
    stringConcatCompact(str3, str4);
    printf("\nCompact concat: \"%s\"\n", str3);
    
    return 0;
}

View the complete Pointersarrays programs page.

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