---
title: "Switch statement in decision making"
subject: "Computer Programming"
chapter: 5
key: "semester_1/computer_programming:switch-decision-making"
source: https://www.bctengineer.com/q/semester_1/computer_programming/switch-decision-making
site: BCT Engineering
---

# Switch statement in decision making

Computer Programming · Chapter 5: Control statements

- Asked in: 2072 Chaitra, 4 marks
- Video: [Conditionals (Switch)](https://www.youtube.com/watch?v=-JMSaLRqsgo) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/switch-decision-making
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-5

## Question

How is the switch statement used in decision making? Explain with a suitable example.

## Short answer

switch evaluates an expression once, compares it with constant case labels, and executes the matching block. break exits the switch; default handles no match. For instance, a day number input prints the day name, making multi‑way selection cleaner than multiple if‑else.

## Answer

The `switch` statement selects one of many blocks of code by comparing the value of an integer or character expression with the constant values of the `case` labels. The matching case is executed; `break` leaves the switch; `default` runs when no case matches.

**Syntax:**
```text
switch (expression)
{
    case value1: statements; break;
    case value2: statements; break;
    default: statements;
}
```

**Example:**
```c
#include <stdio.h>
int main(void)
{
    int day;
    printf("Enter day number (1-7): ");
    scanf("%d", &day);
    switch (day)
    {
        case 1: printf("Sunday\n");    break;
        case 2: printf("Monday\n");    break;
        case 3: printf("Tuesday\n");   break;
        case 4: printf("Wednesday\n"); break;
        case 5: printf("Thursday\n");  break;
        case 6: printf("Friday\n");    break;
        case 7: printf("Saturday\n");  break;
        default: printf("Invalid day\n");
    }
    return 0;
}
```
For input `3`:
```text
Enter day number (1-7): Tuesday
```

It makes multi-way decisions simple and more readable than a long if-else ladder.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does switch compare the expression with?
   A. The constant values of the case labels
   B. Other variables in the program
   C. Floating-point ranges
   D. Strings stored in arrays
   Answer: A. The integer or character expression is matched against constant case labels. (Key point: Switch purpose)

2. What does break do inside a case?
   A. Restarts the switch
   B. Leaves the switch after that case runs
   C. Jumps to default always
   D. Ends the whole program
   Answer: B. break transfers control out of the switch. (Key point: Role of break)

3. When does default run?
   A. Always, before the cases
   B. Only when the expression is 0
   C. When no case matches the expression
   D. Only after the last case matches
   Answer: C. default handles values not covered by any case. (Key point: Default)

4. In the day example, input 3 prints which output?
   A. Monday
   B. Wednesday
   C. Invalid day
   D. Tuesday
   Answer: D. Case 3 is Tuesday in the program. (Key point: Example result)

## Related in Computer Programming

- [scanf with %s and no ampersand](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Ascanf-string-no-ampersand) — Computer Programming, chapter 4

## Related in other subjects

- [Principles of engineering economics and decision making](https://www.bctengineer.com/question.md?key=semester_6%2Fengineering_economics%3Aprinciples-ee-help-decision) — Engineering Economics, chapter 1
- [IS supports managers in decision making](https://www.bctengineer.com/question.md?key=semester_8%2Finformation_system%3Ais-supports-decision-making-quality) — Information System, chapter 1
- [Decision making levels and stages](https://www.bctengineer.com/question.md?key=semester_8%2Fconstruction_management%3Adecision-making-levels) — Construction Management, chapter 10
- [Space switch and why TST is used](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Aspace-switch-why-tst) — Telecommunications, chapter 4
