Following switch execution

A controller calculates a credit value using the following C code. Each table row is an independent execution: credits starts at 2, and mode has the value shown. Enter the final value of credits as an exact integer for every row.


C
int credits = 2;

switch (mode) {
    case 1:
        credits += 3;
    case 2:
        credits *= 2;
        break;
    case 3:
        credits -= 1;
    default:
        credits += 4;
}
modeFinal credits
1
2
3
8

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Data and Control Structures in C Questions: