R21 Generate all binary strings of length N Dry Run in C

R21 Generate all binary strings of length N 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.

R21 Generate all binary strings of length N Program Code

#include <stdio.h>

void generateBinary(int n, char str[], int pos) {
    if(pos == n) {
        str[pos] = '\0';
        printf("%s\n", str);
        return;
    }
    str[pos] = '0';
    generateBinary(n, str, pos+1);
    str[pos] = '1';
    generateBinary(n, str, pos+1);
}

int main() {
    int n = 3;
    char buffer[4];
    printf("All binary strings of length %d:\n", n);
    generateBinary(n, buffer, 0);
    return 0;
}

View the complete Recursion programs page.

Program Console R21 Generate all binary strings of length N Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.