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

Objective Question of Computer Networking

  1.    Choose the correct meaning of the Greek word ‘tele’ in       context of telecommunication. A.   Near B.   Far C.   Never D.   Always   2.    Find the correct term used for the standards that have       been legislated by an officially recognized body.    A.   De jure B.   De facto C.   User standards D.   Channel standards   3.    Which agency developed standards for physical       connection interfaces and electronic signaling       specifications?      A.    ISO B.    ITU C.    ANSI D.    EIA   4.     Find full form of ANSI. A.    American Network Signal Institute B.    American National Signal Institute C.    American National Standards Institute D.    American Network Standards Institute   5.    Select the correct option to complete the following       statement.       The __________ defines the characteristics of the       interface between the devices and the transmission       medium. A.    Transport layer