switch statement c++
C++
switch(expression) {
case constant-expression :
statement(s);
break; //optional
case constant-expression :
statement(s);
break; //optional
// you can have any number of case statements.
default : //Optional
statement(s);
}
switch (n)
{
case 1: // code to be executed if n = 1;
break;
case 2: // code to be executed if n = 2;
break;
default: // code to be executed if n doesn't match any cases
}switch(expression) {
case 1:
//equivalent to if(expression == 1){//do someting...}
//do something...
break;
//if case 1 is true the rest of the statments arn't
//evaluated because of the break
case 45:
//equivalent to else if(expression == 45){//do someting...}
//do something...
break;
// you can have any number of case statements and default has to be last
default :
// equivalent to else{//do someting...}
//do something...
}
switch(expression) {
case 1:
//equivalent to if(expression == 1){//do someting...}
//do something...
case 45:
//equivalent to if(expression == 45){//do someting...}
//do something...
default :
//always runs if there are no breaks in any of the cases
//do something...
}
//modification of answer by Homeless Hoopoe
Also in C++:
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- getline in c++
- Category
- C++
- Title
- strchr function in c++
- Category
- C++
- Title
- formal parameter c++
- Category
- C++
- Title
- fast io c++
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- what is atoi in strinf
- Category
- C++
- Title
- check an stack is empty c++
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- find upper bound c++ vector
- Category
- C++
- Title
- find number of 1s in a binary cv::mat image
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- font awesome bootstrap cdn
- Category
- C++
- Title
- linkedlist implementation in c++
- Category
- C++
- Title
- std::substring
- Category
- C++
- Title
- heap sort
- Category
- C++
- Title
- loop c++
- Category
- C++
- Title
- qt graphics scene map cursor position
- Category
- C++
- Title
- pop from between string c++
- Category
- C++
- Title
- can you use rand to read in from an external file inc++
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- array 2d to 1d
- Category
- C++
- Title
- how to print a 2d array in c++
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- c++ convert int to cstring
- Category
- C++
- Title
- typeid to string c++
- Category
- C++
- Title
- c++ short if
- Category
- C++
- Title
- cout value c++
- Category
- C++
- Title
- how to convert string into number
- Category
- C++
- Title
- c++ multidimensional vector
- Category
- C++
- Title
- c++ delete printed characters
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- if not defined c++
- Category
- C++
- Title
- tokenize string c++
- Category
- C++
- Title
- how are graphics in games made
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- gfg right view of tree
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- __builtin_ctz
- Category
- C++
- Title
- invalid types int int for array subscript c++
- Category
- C++
- Title
- how to reverse a vector
- Category
- C++
- Title
- find height of a tree
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- how to input multiple lines of a file in c++
- Category
- C++
- Title
- array sort c++
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- linear search in c++
- Category
- C++
- Title
- split string at index c++
- Category
- C++
- Title
- declaring vector c++
- Category
- C++
- Title
- gcd in c++
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- c++ isalphanum
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- bool function in c++
- Category
- C++
- Title
- array as parameter c++
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- stringstream in c++
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- ue4 modular character
- Category
- C++
- Title
- for loop
- Category
- C++
- Title
- Find the minimum difference between pairs in a simple path of tree C++
- Category
- C++
- Title
- class in c++
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- delete 2d dynamic array c++
- Category
- C++
- Title
- eratosthenis sieve in c++
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- nth_element c++
- Category
- C++
- Title
- minimum swaps to sort an array
- Category
- C++
- Title
- mark occurances of elements in array cpp
- Category
- C++
- Title
- log base e synthax c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- multiset c++
- Category
- C++
- Title
- find vector in c++
- Category
- C++
- Title
- prims c++
- Category
- C++
- Title
- clear qlayout
- Category
- C++
- Title
- size of a matrix using vector c++
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- how to format decimal palces in c++
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- checking an int in c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- how to print 5 precision float in c++
- Category
- C++
- Title
- int to float c++
- Category
- C++
- Title
- c++ parse int
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- namespace file linking c++
- Category
- C++
- Title
- c++ class method example
- Category
- C++