totally confused!
Advertising
Code: Select all
int main()
{
int x = 1;
switch(x)
{
case 1:
std::cout << "1\n";
break;
case 2:
std::cout << "2\n";
break;
case 3:
std::cout << "3\n";
break;
default:
std::cout << "Unknown\n";
}
return 0;
}
Code: Select all
int main()
{
int x = 1;
if( x >= 1 && x <= 3 )
std::cout << "1-3\n";
else if( x >= 4 && x <= 40 )
std::cout << "4-40\n";
else if( x >= 41 && x <= 100 )
std::cout << "41-100\n";
else
std::cout << "Unknown\n";
}
return 0;
}
only when the presented integers are in a small enough range to be used as indexes for an array of pointers or in the range of the program's codewololo wrote:switch is faster