I am trying to understand the switch statement in C (I am using gcc from Ubuntu v16.04). I am able to understand its semantics, but have the following 2 questions about its syntax:
I have noticed after reading a few examples of usage of switch statement that the symbol after case is sometimes enclosed in
''
and sometimes it isn't. eg:case 1
orcase 'a'
. I checked the Linux manpage for the switch statement (https://linux.die.net/man/1/switch) and there they have not used ' ' for a string. So I don't know what to do.Sometimes the block of code within a single case is enclosed in a
{ }
and sometimes it is not. I had read before that multi-line statements need to be enclosed in a{ }
, but not necessarily for single-line statements as in a for loop,while loop with single line statements etc. But sometimes a case statement has 1 line of code (for ega *= 5;
) followed bybreak
statement (so total 2 statements) and yet both lines are not enclosed in{ }
. The Linux manpages haven't mentioned this. Can someone clarify this?