R22 Generate all strings from given characters Dry Run in C

R22 Generate all strings from given characters is an interactive C dry run visualizer from the Recursion 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.

R22 Generate all strings from given characters Program Code

#include <stdio.h>

void generateStrings(char chars[], int k, char str[], int pos, int n) {
    if(pos == k) {
        str[pos] = '\0';
        printf("%s\n", str);
        return;
    }
    for(int i = 0; i < n; i++) {
        str[pos] = chars[i];
        generateStrings(chars, k, str, pos+1, n);
    }
}

int main() {
    char chars[] = {'A', 'B', 'C'};
    int length = 2;
    char buffer[3];
    printf("All strings of length %d from {A,B,C}:\n", length);
    generateStrings(chars, length, buffer, 0, 3);
    return 0;
}

View the complete Recursion programs page.

Program Console R22 Generate all strings from given characters Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.