Answers

Question and Answer:

  Home  Basic C++ Syntax

⟩ What is switch case in C++ Syntax?

Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char). The basic format for using switch case is outlined below. The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point.

switch ( ) {

case this-value:

Code to execute if == this-value

break;

case that-value:

Code to execute if == that-value

break;

...

default:

Code to execute if does not equal the value following any of the cases

break;

}

 189 views

More Questions for you: