Something about switch-case
statement is very unclear for me. First of all I could understand the case
part as an if
statement, but what dose switch
do itself? I mean when we pass argument to switch, what happens there?
c=getchar();
switch(c)
2: Why there is no need to put ;
after switch? What kind of the function is it?
3: How compilers implement switch-case
statement at the first time? (just C
or use assembly
)
4: We can't use switch-case
like this:
switch(string)
{
case "aaaa":
...
case "bbbb":
...
we use if-strcmp
instead. Is it possible to create switch-case
like statement for string condition? I see some library like getopt
use struct to handle command line string arguments:
{"help",...,'h'},
{"version",...,'v'}
...
but I want to use string directly.