I started C++ recently and while learning switch case, I got this doubt.
What\'s the difference if I use int or char in the following code :
int Fav_Car;
What's the difference between char and int in a switch case?
Using char or int are both ok in a switch statement. It depends on how you input your Fav_Car - as long as the input matches with a case, that case will be executed.
Note that char is also an integral type - it has a value in range [32, 127] (assume you want a printable char).
what's the difference if I use case '1' : and case "1"
switch case only work with integral (ie int, char). So:
case '1': // ok.
case "1": // wrong because "1" is a string - not integral type.