Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 3 MCQs Control Statements and Decision Making

CAP1008 — C Programming 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 introduction of control statement Easy

    What is the main purpose of control statements in C?

  2. Question 2 of 60 introduction of control statement Easy

    Which of the following is NOT a category of control statements in C?

  3. Question 3 of 60 condition statements Easy

    Conditional statements in C execute a block of code based on the result of a:

  4. Question 4 of 60 if Easy

    In an if statement, the block of code executes only when the condition is:

  5. Question 5 of 60 if Easy

    What is the output of the following code?
    c
    int x = 5;
    if (x > 3)
    printf("Yes");

  6. Question 6 of 60 if-else Easy

    In an if-else statement, the else block executes when the condition is:

  7. Question 7 of 60 if-else Easy

    What is the output of the following code?
    c
    int a = 2;
    if (a == 5)
    printf("Equal");
    else
    printf("Not Equal");

  8. Question 8 of 60 nested if and switch statement Easy

    A nested if statement means:

  9. Question 9 of 60 nested if and switch statement Easy

    Which keyword is used to define the default case in a switch statement?

  10. Question 10 of 60 nested if and switch statement Easy

    What happens if break is omitted after a matching case in a switch statement?

  11. Question 11 of 60 nested if and switch statement Easy

    The expression used in a switch statement must evaluate to which type of value?

  12. Question 12 of 60 looping statements-while and do-while loop Easy

    In a while loop, when is the condition checked?

  13. Question 13 of 60 looping statements-while and do-while loop Easy

    How many times is the body of a do-while loop guaranteed to execute at minimum?

  14. Question 14 of 60 looping statements-while and do-while loop Easy

    Which loop checks its condition at the end (bottom) of the loop?

  15. Question 15 of 60 looping statements-while and do-while loop Easy

    What is the output of the following code?
    c
    int i = 1;
    while (i <= 3) {
    printf("%d", i);
    i++;
    }

  16. Question 16 of 60 for loop Easy

    In a for loop, which part is executed only once, at the very beginning?

  17. Question 17 of 60 for loop Easy

    How many times will the following loop print Hi?
    c
    for (int i = 0; i < 4; i++)
    printf("Hi");

  18. Question 18 of 60 break and continue statements Easy

    What does the break statement do inside a loop?

  19. Question 19 of 60 break and continue statements Easy

    What does the continue statement do inside a loop?

  20. Question 20 of 60 goto statement Easy

    The goto statement transfers control to a:

  21. Question 21 of 60 introduction of control statement Medium

    Which category of control statements is used to repeatedly execute a block of code based on a condition?

  22. Question 22 of 60 condition statements Medium

    What is the value of the expression 5 > 3 && 2 < 1 in C?

  23. Question 23 of 60 if Medium

    What does the following code print?

    C
    int x = 10;
    if (x = 5)
        printf("Yes");
    else
        printf("No");

  24. Question 24 of 60 if-else Medium

    What is the output of the following code?

    C
    int a = 7;
    if (a % 2 == 0)
        printf("Even");
    else
        printf("Odd");

  25. Question 25 of 60 nested if and switch statement Medium

    In the code below, which else does the inner if associate with?

    C
    if (a > 0)
        if (b > 0)
            printf("A");
    else
        printf("B");

  26. Question 26 of 60 nested if and switch statement Medium

    What is the output of the following switch statement?

    C
    int n = 2;
    switch (n) {
        case 1: printf("One");
        case 2: printf("Two");
        case 3: printf("Three");
        default: printf("None");
    }

  27. Question 27 of 60 nested if and switch statement Medium

    Which data type is NOT allowed as a switch expression in C?

  28. Question 28 of 60 looping statements-while and do-while loop Medium

    How many times does the body of this loop execute?

    C
    int i = 5;
    while (i < 5) {
        printf("%d", i);
        i++;
    }

  29. Question 29 of 60 looping statements-while and do-while loop Medium

    How many times does the body of this loop execute?

    C
    int i = 5;
    do {
        printf("%d", i);
        i++;
    } while (i < 5);

  30. Question 30 of 60 looping statements-while and do-while loop Medium

    What is the final value printed by this code?

    C
    int sum = 0, i = 1;
    while (i <= 4) {
        sum += i;
        i++;
    }
    printf("%d", sum);

  31. Question 31 of 60 for loop Medium

    What is the output of the following code?

    C
    for (int i = 0; i < 3; i++)
        printf("%d ", i * i);

  32. Question 32 of 60 for loop Medium

    How many times does the following loop execute?

    C
    for (int i = 10; i > 0; i -= 3)
        printf("*");

  33. Question 33 of 60 for loop Medium

    What happens when all three expressions of a for loop are omitted, as in for(;;)?

  34. Question 34 of 60 break and continue statements Medium

    What is the output of the following code?

    C
    for (int i = 1; i <= 5; i++) {
        if (i == 3)
            break;
        printf("%d ", i);
    }

  35. Question 35 of 60 break and continue statements Medium

    What is the output of the following code?

    C
    for (int i = 1; i <= 5; i++) {
        if (i % 2 == 0)
            continue;
        printf("%d ", i);
    }

  36. Question 36 of 60 break and continue statements Medium

    In nested loops, what does a break statement inside the inner loop terminate?

  37. Question 37 of 60 goto statement Medium

    What is the output of the following code?

    C
    int i = 0;
    start:
    printf("%d ", i);
    i++;
    if (i < 3)
        goto start;

  38. Question 38 of 60 goto statement Medium

    Which statement about the goto statement in C is correct?

  39. Question 39 of 60 if-else Medium

    What is the output of this ternary-based code?

    C
    int a = 4, b = 9;
    int max = (a > b) ? a : b;
    printf("%d", max);

  40. Question 40 of 60 for loop Medium

    What is the output of the following nested loop?

    C
    for (int i = 1; i <= 2; i++)
        for (int j = 1; j <= 2; j++)
            printf("%d%d ", i, j);

  41. Question 41 of 60 if-else Hard

    What is the output of the following code?

    C
    #include <stdio.h>
    int main() {
        int a = 5, b = 10;
        if (a > b)
            if (a > 0)
                printf("X");
        else
            printf("Y");
        return 0;
    }

  42. Question 42 of 60 switch statement Hard

    What does this program print?

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

  43. Question 43 of 60 for loop Hard

    What is the output of the following code?

    C
    #include <stdio.h>
    int main() {
        int i, sum = 0;
        for (i = 1; i <= 10; i++) {
            if (i % 2 == 0) continue;
            if (i > 7) break;
            sum += i;
        }
        printf("%d", sum);
        return 0;
    }

  44. Question 44 of 60 looping statements-while and do-while loop Hard

    What is printed by this code?

    C
    #include <stdio.h>
    int main() {
        int i = 5;
        do {
            printf("%d ", i);
            i -= 2;
        } while (i > 0);
        return 0;
    }

  45. Question 45 of 60 for loop Hard

    What is the output?

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

  46. Question 46 of 60 nested if Hard

    For which value of n does this print Match?

    C
    if (n > 0) {
        if (n % 3 == 0) {
            if (n % 2 != 0)
                printf("Match");
        }
    }

  47. Question 47 of 60 goto statement Hard

    What is the output of this code?

    C
    #include <stdio.h>
    int main() {
        int i = 0, sum = 0;
    loop:
        i++;
        if (i == 3) goto skip;
        sum += i;
    skip:
        if (i < 5) goto loop;
        printf("%d", sum);
        return 0;
    }

  48. Question 48 of 60 break and continue statements Hard

    What is the output of the nested loop?

    C
    #include <stdio.h>
    int main() {
        int i, j, c = 0;
        for (i = 1; i <= 3; i++) {
            for (j = 1; j <= 3; j++) {
                if (j == 2) break;
                c++;
            }
        }
        printf("%d", c);
        return 0;
    }

  49. Question 49 of 60 switch statement Hard

    What does the following print?

    C
    #include <stdio.h>
    int main() {
        int x = 1, y = 0;
        switch (x) {
            case 1: y += 1;
            case 2: y += 2;
            default: y += 10;
            case 3: y += 3;
        }
        printf("%d", y);
        return 0;
    }

  50. Question 50 of 60 for loop Hard

    What is the output?

    C
    #include <stdio.h>
    int main() {
        int i, j;
        for (i = 0, j = 10; i < j; i++, j--)
            ;
        printf("%d %d", i, j);
        return 0;
    }

  51. Question 51 of 60 looping statements-while and do-while loop Hard

    What is the output of this program?

    C
    #include <stdio.h>
    int main() {
        int i = 1;
        while (i <= 100) {
            i *= 2;
        }
        printf("%d", i);
        return 0;
    }

  52. Question 52 of 60 if-else Hard

    What does this print for the assignment shown?

    C
    #include <stdio.h>
    int main() {
        int a = 3, b = 5;
        int max = (a > b) ? a : (b > 10 ? b : a + b);
        printf("%d", max);
        return 0;
    }

  53. Question 53 of 60 break and continue statements Hard

    What is the output?

    C
    #include <stdio.h>
    int main() {
        int i = 0;
        while (i < 5) {
            i++;
            if (i == 3) continue;
            printf("%d", i);
        }
        return 0;
    }

  54. Question 54 of 60 switch statement Hard

    Which statement about this code is correct?

    C
    int x = 2;
    switch (x) {
        case 1.5: printf("A"); break;
        case 2: printf("B"); break;
    }

  55. Question 55 of 60 for loop Hard

    What is the output of this code?

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

  56. Question 56 of 60 nested if Hard

    What is printed?

    C
    #include <stdio.h>
    int main() {
        int a = 0;
        if (a = 5)
            if (a == 5)
                printf("P");
            else
                printf("Q");
        else
            printf("R");
        return 0;
    }

  57. Question 57 of 60 looping statements-while and do-while loop Hard

    How many times does the body execute?

    C
    int i = 10;
    while (i-- > 0) {
        // body
    }

  58. Question 58 of 60 goto statement Hard

    What does this code output?

    C
    #include <stdio.h>
    int main() {
        int i = 1;
        start:
        if (i <= 3) {
            printf("%d", i);
            i++;
            goto start;
        }
        printf("End");
        return 0;
    }

  59. Question 59 of 60 condition statements Hard

    What is the output?

    C
    #include <stdio.h>
    int main() {
        int x = 5, y = 5, z;
        z = x++ || ++y;
        printf("%d %d %d", x, y, z);
        return 0;
    }

  60. Question 60 of 60 introduction of control statement Hard

    Which classification correctly groups these C control statements?

    1. if, if-else, switch
    2. while, do-while, for
    3. break, continue, goto, return

That's unit 3

Answer a few questions and your score shows up here.