Skills101
← All practice quizzes

Quiz: C Control Flow

5 questionsNo time limitPass: 60%+10 XP on first pass

Decisions and loops in C with clear examples: if-else ladders, switch with fall-through, the three loops, break and continue, nested loops and pattern programs.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    #include <stdio.h>
    int main(void) {
        int x = 2;
        switch (x) {
            case 1: printf("A");
            case 2: printf("B");
            case 3: printf("C");
            default: printf("D");
        }
        return 0;
    }
    
  2. Question 2

    What does this print?

    #include <stdio.h>
    int main(void) {
        int i;
        for (i = 0; i < 5; i++);
        printf("%d", i);
        return 0;
    }
    
  3. Question 3

    What does this print?

    #include <stdio.h>
    int main(void) {
        int x = 0;
        if (x = 0) printf("yes");
        else printf("no");
        return 0;
    }
    
  4. Question 4

    Which loop always runs its body at least once?

  5. Question 5

    What does this print?

    #include <stdio.h>
    int main(void) {
        int count = 0;
        for (int i = 1; i <= 20; i++) {
            if (i % 3 == 0) count++;
        }
        printf("%d", count);
        return 0;
    }