CodersEditor Tutorials

CodersEditor Tutorials

  • Online IDE
  • Q&A
  • C Programming
  • Java
  • GraphQL.NET
  • System Software

›Control Flow/Decision Making

C Programming

    Introduction

    • Overview
    • Installation & Setup
    • C Program Structure
    • Keywords & Identifiers
    • Data Types
    • Variables & Constants
    • Scope Rules
    • Storage Class
    • Standard Input and Output
    • Operators

    Control Flow/Decision Making

    • Overview
    • if Statement
    • if else Statement
    • Nested If statement
    • Switch Statement
    • Nested Switch Statement
    • Conditional Operators

    Loop

    • Loops Overview
    • While loop
    • For Loop
    • Do while
    • Nested Loops
    • Break
    • Continue Statement
    • Goto statement

    Arrays

    • Arrays
    • Multi Dimensional Arrays
    • Arrays & Functions

    Pointers

    • Pointers Basics
    • Pointers and Arrays
    • Pointers and Functions
    • Memory allocation

    Strings

    • String Basics
    • String Functions

    C Programming Examples

    • Basic Example 1

Nested Switch Statement in C

In this article you will learn about the Nested Switch statement in C programming and how it can be used in a C program.

Nested Switch Statement in C

As the name says Nested-Switch statements is nothing but the Switch statement inside another Switch Statement. The first switch is known as an outer switch statement whereas the inside switch is the inner switch statement.

The Nested Switch statement is used when you have to choose a option inside another option. The outer switch will be a set of options and the inner switch is the set of options given inside the options in outer switch.

Syntax:

switch(char) 
{
 case 'X': 
   printf("outer switch" );
  switch(char1)
   {
     case 'X':
       printf("inner switch" );
       break;
     case 'Y': /* code 
   }
  break;
   case 'Y': /* code 
  }

Example

#include <stdio.h>
int main () 
{
    int x = 10;
    int y = 20;
    switch(x) 
    {
        case 10: 
            printf("outer switch\n", x );
            switch(y) 
            {
                case 20:
                printf("inner switch\n", x );
            }
    }
    printf("value of x is : %d\n", x);
    printf("value of y is : %d\n", y);
    return 0;
}

Output

outer switch
inner switch
value of x is : 10
value of y is : 20
← Switch StatementConditional Operators →
  • Nested Switch Statement in C
  • Syntax:
  • Example
CodersEditor Tutorials
CoderdEditor Developer Tools
CodersEditor Online EditorGit Flavoured Markup EditorFree Online JSON FormatterFind My IP Address Details
Tutorials
C ProgrammingJava
Copyright © 2021 CodersEditor.com