Area of Improvements
Review your assessments and practice — drill into each subject, then each attempt, then each question.
Question 3 of 10
Compare control structures (if/else vs switch) in C and discuss trade-offs.
Switch is faster than if-else I think, because the compiler makes a jump table. If-else is more flexible because you can do ranges and stuff. You always need break in switch otherwise it falls through.
if/else handles arbitrary boolean expressions including ranges and compound conditions; switch dispatches on a single integer/char value and is often compiled to a jump table for O(1) dispatch on dense cases. Switch requires break to prevent fallthrough (intentional fallthrough is a common bug source). Prefer switch for many discrete equality checks on the same variable, if/else for ranges or complex predicates.
- Notes switch dispatches on integral/char only
- Mentions jump-table optimisation for switch
- Calls out fallthrough behaviour and break
- Recommends if/else for ranges or complex predicates
- Discusses readability/maintenance trade-off
- Did not give a concrete rule for when to choose each
- Said switch is 'always' faster than if/else

