Nested Switch Statement Dry Run in C

Nested Switch Statement is an interactive C dry run visualizer from the Switch 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.

Nested Switch Statement Program Code

#include <stdio.h>
int main() {
    int category, item;
    
    printf("1. Electronics\n2. Clothing\nEnter category: ");
    scanf("%d", &category);
    
    switch(category) {
        case 1:
            printf("1. Mobile\n2. Laptop\nEnter item: ");
            scanf("%d", &item);
            switch(item) {
                case 1:
                    printf("Mobile - ₹15000\n");
                    break;
                case 2:
                    printf("Laptop - ₹50000\n");
                    break;
                default:
                    printf("Invalid item\n");
            }
            break;
        case 2:
            printf("1. Shirt\n2. Pants\nEnter item: ");
            scanf("%d", &item);
            switch(item) {
                case 1:
                    printf("Shirt - ₹1000\n");
                    break;
                case 2:
                    printf("Pants - ₹1500\n");
                    break;
                default:
                    printf("Invalid item\n");
            }
            break;
        default:
            printf("Invalid category\n");
    }
    return 0;
}

View the complete Switch programs page.

Program Console Nested Switch Statement Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.