C switch...case Statement

You are Here:

C switch...case Statement

The switch...case statement executes a block of code depending on different cases.

Syntax

switch(expression){ case x: // code block case y: // code block default: // code block }

Example Program

Note: The statements under default will be executed when no match is found in cases.

C Compiler
#include <stdio.h> int main() { int num = 5; char *txt= ".com"; switch(num){ case 0: txt = "zero"; break; case 1: txt = "One"; break; case 2: txt = "Two"; break; default: txt = "no match"; } printf("Text is %s",txt); return 0; }

Output

Text is no match
congratulation

Congratulation! you have learned everything about switch...case statement in C Programming.

Reminder

Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author