Using Range in switch Case in C Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report You all are familiar with switch case in C, but did you know you can use a range of numbers instead of a single number or character in the case statement? Range in switch case can be useful when we want to run the same set of statements for a range of numbers so that we do not have to write cases separately for each value. That is the case range extension of the GNU C compiler and not standard C.You can specify a range of consecutive values in a single case label.Syntax The syntax for using range case is: case low ... high: It can be used for a range of ASCII character codes like this: case 'A' ... 'Z': You need to Write spaces around the ellipses ( ... ). For example, write this: // Correct - case 1 ... 5: // Wrong - case 1...5: The below program illustrates the use of range in switch case. C // C program to illustrate // using range in switch case #include <stdio.h> int main() { int arr[] = { 1, 5, 15, 20 }; for (int i = 0; i < 4; i++) { switch (arr[i]) { // range 1 to 6 case 1 ... 6: printf("%d in range 1 to 6\n", arr[i]); break; // range 19 to 20 case 19 ... 20: printf("%d in range 19 to 20\n", arr[i]); break; default: printf("%d not in range\n", arr[i]); break; } } return 0; } Output1 in range 1 to 6 5 in range 1 to 6 15 not in range 20 in range 19 to 20Complexity AnalysisTime Complexity: O(n), where n is the size of array arr.Auxiliary Space: O(1)Error conditionslow > high: The compiler gives an error message.Overlapping case values: If the value of a case label is within a case range that has already been used in the switch statement, the compiler gives an error message.ExerciseYou can try the above program for a char array by modifying the char array and case statement. Comment More infoAdvertise with us K kartik Improve Article Tags : C++ C Basics cpp-switch Practice Tags : CPP Explore Introduction to C++Introduction to C++ Programming Language3 min readHeader Files in C++5 min readSetting up C++ Development Environment8 min readDifference between C and C++3 min readBasicsC++ Data Types7 min readC++ Variables4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readC++ Loops7 min readFunctions in C++8 min readC++ Arrays8 min readStrings in C++5 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readC++ OOPInheritance in C++10 min readC++ Polymorphism5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Containers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library2 min readPractice C++C++ Interview Questions and Answers (2025)15+ min readTop C++ DSA Related ProblemsC++ Programming Examples7 min read Like