Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) default

 

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");
  }
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict