Print string using pointer Dry Run in C

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

Print string using pointer Program Code

#include <stdio.h>
int main() {
    char str[] = "Hello, World!";
    char *ptr = str;
    int i;
    
    // Method 1: Using array indexing
    printf("Method 1 (array): %s\n", str);
    
    // Method 2: Using pointer with index
    printf("Method 2 (ptr index): ");
    for(i = 0; ptr[i] != '\0'; i++) {
        printf("%c", ptr[i]);
    }
    printf("\n");
    
    // Method 3: Using pointer arithmetic
    printf("Method 3 (ptr arithmetic): ");
    for(i = 0; *(ptr + i) != '\0'; i++) {
        printf("%c", *(ptr + i));
    }
    printf("\n");
    
    // Method 4: Using pointer increment
    printf("Method 4 (ptr++): ");
    ptr = str;
    while(*ptr != '\0') {
        printf("%c", *ptr);
        ptr++;
    }
    printf("\n");
    
    return 0;
}

View the complete Pointersarrays programs page.

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