About 234,000 results
Open links in new tab
  1. 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: #include<stdio.h> int main() {

  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 noticed a...

  3. 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 source...

  4. c - Switch statement with returns -- code correctness - Stack Overflow

    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. …

  5. c - Should we break the default case in switch statement ... - Stack ...

    Oct 1, 2014 · Should we use a break; in the last default case? From The C programming language - Second edition (K&R 2): Chapter 3.4 Switch As a matter of good form, put a break after the last case …

  6. 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 statements …

  7. c - How to write switch statement with "or" logic? - Stack Overflow

    Mar 10, 2013 · Below, I have created a simple switch statement that works fine. I was wondering how I could change this code so it is switch(c), then case 1, case 2, case 3, default. Example: if char is 'w' || ...

  8. How can I use ranges in a switch case statement in C?

    Apr 20, 2016 · In the C programming language the case statement used in a switch() statement must specify a value that the compiler can turn into a constant in some way. Each of the values used in …

  9. c - When to use 'if' vs 'switch' statements? - Stack Overflow

    Oct 28, 2016 · In theory, you can frame any if-else block with either a single switch statement or nested switch statements. In practice, a switch statement works well with a single integral value.

  10. 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.