Copy string using pointer Dry Run in C

Copy 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.

Copy string using pointer Program Code

#include <stdio.h>
void stringCopy(char *dest, char *src) {
    while(*src != '\0') {
        *dest = *src;
        dest++;
        src++;
    }
    *dest = '\0';  // Add null terminator
}

void stringCopyCompact(char *dest, char *src) {
    while(*dest++ = *src++);
}

int main() {
    char source[] = "Hello, Pointer World!";
    char dest1[50], dest2[50];
    
    printf("Source: \"%s\"\n", source);
    
    stringCopy(dest1, source);
    printf("Dest1 (explicit): \"%s\"\n", dest1);
    
    stringCopyCompact(dest2, source);
    printf("Dest2 (compact): \"%s\"\n", dest2);
    
    // Demonstrate the compact version works
    printf("\nDemonstrating compact copy:\n");
    char str1[] = "ABC";
    char str2[10];
    char *p = str2;
    char *src = str1;
    while(*p++ = *src++);
    printf("Copied: \"%s\"\n", str2);
    
    return 0;
}

View the complete Pointersarrays programs page.

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