Skip to content

Latest commit

 

History

History
39 lines (22 loc) · 1.66 KB

CppDefault.md

File metadata and controls

39 lines (22 loc) · 1.66 KB

 

 

 

 

 

 

default is a keyword used in a switch statement. If there is no case to switch on, default can be used optionally for non-case values.

 


#include <cassert> #include <iostream> int main() {   const int dice = 1 + (std::rand() % 6);   switch (dice)   {     case 1: std::cout << "One\n"; break;     case 2: std::cout << "Two\n"; break;     case 3: std::cout << "Three\n"; break;     case 4: std::cout << "Four\n"; break;     case 5: std::cout << "Five\n"; break;     case 6: std::cout << "Six\n"; break;     default: assert(!"Should not get here");   } }