About 235,000 results
Open links in new tab
  1. How can I compare strings in C using a `switch` statement?

    In C there is a switch construct which enables one to execute different conditional branches of code based on an test integer value, e.g., int a; /* Read the value of "a" from some …

  2. Syntax of switch statement in C? - Stack Overflow

    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 …

  3. c - Switch statement with returns -- code correctness - Stack …

    Jun 18, 2010 · Personally I would remove the returns and keep the breaks. I would use the switch statement to assign a value to a variable. Then return that variable after the switch statement. …

  4. c - Is 'switch' faster than 'if'? - Stack Overflow

    With the switch statement, there's almost no difference in speed between a 2-way and a 10-way test, as long as the values are dense. The 10-way test with sparse values takes about 1.6x as …

  5. Larger than and less than in C switch statement

    Switch can't handle ranges as you have shown, but you could find a way to include switch by categorising the input first (using if/else) then using a switch statement to output the answer.

  6. C Switch-case curly braces after every case - Stack Overflow

    May 29, 2015 · In a C switch-case flow control, it's required to put curly braces { } after a case if variables are being defined in that block. Is it bad practice to put curly braces after every case, …

  7. c - How does switch statement work? - Stack Overflow

    Feb 23, 2012 · How are statements that come before any case labelled statement in a switch-case block treated. Please explain the behavior of the following programs prog1: …

  8. c - Switch statement: must default be the last case? - Stack Overflow

    The case statements and the default statement can occur in any order in the switch statement. The default clause is an optional clause that is matched if none of the constants in the case …

  9. c - Use switch with number case and char case - Stack Overflow

    Nov 18, 2016 · Others have suggested using %c so that your not mixing characters with integers but you need to be careful with the rest of the code. You may need a cast for the switch …

  10. Why can't variables be declared in a switch statement?

    Sep 18, 2008 · I've always wondered this - why can't you declare variables after a case label in a switch statement? In C++ you can declare variables pretty much anywhere (and declaring …