UrbanPro

Learn C++ Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How a switch statement works internally. That is how does it find which does it need to execute?

Asked by Last Modified  

Follow 6
Answer

Please enter your answer

How switch is implemented depends on what values you have. For values that are close in range, the compiler will generally generate a jump table. If the values are far apart, it will generate a linked branch, using something like a binary search to find the right value.
Comments

IT Professional Trainer

Switch is especially useful as check point for multiple conditions. Syntax: Switch(condition) { case 1: logic ;break; case 2 :logic; break; default : logic; } .switch statement checks condtion or choice and look for right case and execute the logic and then break the execution flow. if it did not...
read more

Switch is especially useful as check point for multiple conditions.  Syntax: Switch(condition) {  case 1: logic ;break; case 2 :logic; break; default : logic; } .switch statement checks condtion or choice  and look for right case and execute the logic and then break the execution flow. if it did not find the any matched case , it will execute default  block.
ex: int day=1;
switch(day){
case 1:
          print("Monday");
           break;
case 2:
          print("Tuesday");
           break;
case 1:
          print("Wednesday");
           break;
case 1:
          print("Thursday");
           break;
case 1:
          print("Friday");
           break;
case 1:
          print("saturday");
           break;
Default:
          Print("Sunday");
}

read less
Comments

Be Good Do Good

result of condition is true or false we use if condition When there are more than two options we use switch statement compiler checks the case statement from top to down any case matches with the conditions it executes the blocks until break encounters other wise it edecutes default statements
read more

result of condition is true or false we use if condition

When there are more than two options we use switch statement

compiler checks the case statement from top to down any case matches with the conditions it executes the blocks until break encounters  other wise it edecutes default statements 

 

read less
Comments

Software Trainer with 10 years of experience

switch statement is a choice based selection statement syntax: switch(choice) {case 1:statements; break; case 2:statements; break; .. case value matching with the input value of choice will be executed. case value can be integer or character
read more

switch statement is a choice based selection statement

syntax:

switch(choice)

{
case 1:statements;

break;

case 2:statements;

break;

..

case value matching with the input value of choice will be executed.

case value can be integer or character 

read less
Comments

View 2 more Answers

Related Questions

Which language is best, C, C++, Python or Java?
If you want to learn any languages C#, Java, ect. then must to learn C, C++ language as these are base or language to be strong in language skills. C++ is improved version of C language. C#, Java, J# and etc. which are improved version of C++.
Sribaghya
0 0
6
i am a student of 11th class and i want to make my future in C++ is this possible i am take arts inn 11th class
Definitely.. but you should be flexible moving to java/ other languages as well.. requirement/ demand keep changing in software. i can do the needful.. with 18+ yrs exp in working on live projects...
Rajneesh
Is it possible to write big safe programs in C++?
yes. C++ is generally used to write system software. For example windows operating system are writeen in C++. Most of the operating system, device driver and antivirus programs are written by using C++.
Sapna
0 0
6
What are the toughest topics in C language?
1. pointer 2. dynamic memory allocation 3. File handling
Lokayya
0 0
5
Are C Programmers currently in demand?
Ofcourse, C is alwasy in demand. In the beginning a lot of the big project developed in C language. Now a days, there are a lot of language in market and speciallity is growing in IT field. For a big organization...
Harsha

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Is It Fine To Write “void main()” Or “main()” In C/C++?
The definition: void main() { /* ... */ } Is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1 or the ISO C standard 5.1.2.2.1. A conforming...

Predict the Output of C Questions based on Recursion and Macro
#include<stdio.h>void k(unsigned int i,unsigned int j){ static char x="0123456789ABCDEF"; if(i>=j) k(i/j,j); putchar(x);}void main(){ k(20,12);} ___________________________________________ ...

Tress And Its Traversal
Depth First Traversals:(a) Inorder (Left, Root, Right) : 4 2 5 1 3(b) Preorder (Root, Left, Right) : 1 2 4 5 3(c) Postorder (Left, Right, Root) : 4 5 2 3 1 Trees are one of the data structures like...

Importance Of Function Prototype In C
Function prototype tells compiler about number of parameters function takes, data-types of parameters and return type of function. By using this information, compiler cross checks function parameters and...

C, C++, JAVA Tutor
* Program to swap two numbers using a temporary variable with each statement explained with comments * #include // headerfile for cout statement using namespace std; //...

Recommended Articles

Introduction C++ is an excellent programming language and many of the applications are written in C++ language. It has generic, object-oriented & imperative programming features, and also provides facilities for low-level memory manipulation. Successor of C language, it is an OOP (object oriented programming) language...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Looking for C++ Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C++ Language Classes?

The best tutors for C++ Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C++ Language with the Best Tutors

The best Tutors for C++ Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more