Lesson 6 of 23

&&, ||, ! and switch

9 min 25 XP

&& (AND) is true when both sides are true, || (OR) when either is, and ! (NOT) flips a condition. The ternary operator condition ? a : b picks one of two values.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

switch compares one value against many cases. End each case with break, or execution falls through into the next case.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Challenge

+25 XP

Read a letter with scanf(" %c", &ch). Print "Vowel" for a, e, i, o, u (small or capital), otherwise "Consonant". Use switch.

Output Loading C (first time takes a few seconds)
Press Run to see the result here.