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

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
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 C#, C++, Python, or JS better for game development?
All languages good for gamjng. But you can make 3d games in c# uaing unity software and it's very very interesting to work on it.
Mohit
0 0
6
What are the toughest topics in C language?
1. pointer 2. dynamic memory allocation 3. File handling
Lokayya
0 0
5
What is the best IDE for C and C++ development?
If you're a student then Turbo C++ is best for C and C++ program + inbuilt C/C++ Graphics Function If you're a professional or working then Netbeans for C/C++ or Code:: Blocks is Best.
Balakrishnasingh

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

Ask a Question

Related Lessons

Definite book guides for C++
This post attempts to collect the few pearls among the dozens of bad C++ books. Unlike many other programming languages, which are often picked up on the go from tutorials found on the internet, only...

C++ Advanced Course Study With C++11 Features
OOPS(Object Oriented Programming Systems) In C++. Types of Languages 2GL(Basic,Instruction programming to microprocessors/MC), 3GL(COBOL(= EQUALS TO),C++,C,PASCAL,Java,C#) 4GL(HTML,CSS,JSON) Style...

Do You Know Size Of Empty Class and Reason?
Size of empty class is always 1 byte. Reason is, in order to differentiate one object to another object, the size of empty class is always 1 byte. See the below c++ code snippet. Here there are three...

Interview Questions
(1) What is the output of below program: For(char i = 0; i<256; i++)Printf(“%d\n”,i); Modify above program so that it can prints number from 0 to 255. (2) Consider on following declaration: (i)...

Magic in C=> OFFSET OF MACRO in C [offsetof(TYPE, MEMBER)]
Here I am going to discuss an exciting macro in C. It will give you offset of a member within a structure. NULL or 0 address is typecasted to TYPE first. It won't result in segmentation fault as we are...

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