Skip to main content

C++ switch(स्विच)


C++ switch(स्विच)


हेलो स्टूडेंट्स आज मै आपको c++ में स्विच स्टेटमेंट के बारे में बताता हूँ | जब हमको कोई मल्टीप्ल कंडीशंस को एक्सेक्यूटे कराना हो तो हम स्विच स्टेटमेंट का यूज़ करते है | 

The C++ switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement in C++.


switch(expression)
{      
case value1:   
   
 //code to be executed;
      
 break;   

case value2:     

 //code to be executed;  
    
 break;   

......     
default
      
 //code to be executed if all cases are not matched;     

 break
   
}    






Figure No:1





C++ Switch Example(स्विच का उदाहरण )


#include <iostream>  

using namespace std;  

int main () 

{  

       int num;  

       cout<<"Enter a number to check grade:";    

       cin>>num; 

           switch (num)   

//( स्विच के साथ एक्सप्रेशन लिखना होता है)
यहाँ पर num एक वेरिएबल है | 

          {  
  
              case 10: cout<<"It is 10"break;  
  
              case 20: cout<<"It is 20"break;
    
              case 30: cout<<"It is 30"break
   
              default: cout<<"Not 10, 20 or 30"break;  
  
          
}    

    }  


  
Output:

Enter a number:
10
It is 10
Output:


Comments

Popular posts from this blog

Memory Hierarchy

Memory Hierarchy A memory unit is an essential component in any digital computer since it is needed for storing programs and data. Typically, a memory unit can be classified into two categories: The memory unit that establishes direct communication with the CPU is called  Main Memory . The main memory is often referred to as RAM (Random Access Memory). The memory units that provide backup storage are called  Auxiliary Memory . For instance, magnetic disks and magnetic tapes are the most commonly used auxiliary memories. Apart from the basic classifications of a memory unit, the memory hierarchy consists all of the storage devices available in a computer system ranging from the slow but high-capacity auxiliary memory to relatively faster main memory. The following image illustrates the components in a typical memory hierarchy. Auxiliary Memory Auxiliary memory is known as the lowest-cost, highest-capacity and slowest-access storage in a computer system. Auxiliar