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;
In this case: none; there is no difference in the way your program will execute its switch
statement. Both char
and int
are Integral Types: they represent integers. char
is typically unsigned and at least 8 bits (0-255) and int
is signed and typically 32-bits (-2 billion to + 2 billion).
Note that char
represents a single character, not a string; and that you cannot use a string value in a switch
statement in the way you can in C#, Java and Swift, as switch
compiles-down to an in-memory hashtable for ultra-fast performance, that optimization cannot be done with string types currently.