Switch() default

Im confused what is the point of using default in the switch statement instead of using just case?
1
2
3
4
5
6
7
8
9
10
11
uint32_t i = /*xxxx*/;
switch(i)
{
    case 0: show_help(); break;
    case 1: do_stuff(); break;
    //In other cases we want to display an error message to user
    //Using just cases we will just have to cover 4294967294 cases that still left
    //You can do it if you have absolutely nothing to do
    //But most people are using default in this case:
    default: std::cout << "invalide choice\n"; break;
}
Last edited on
Thank you so much I understand now thanks!
Topic archived. No new replies allowed.