Skip to content
QuiznExam

Control Instructions in C

Test your knowledge of control instructions in C, including conditional statements, loops, switch statements, break, continue, and jump statements.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

const in C

15 questions · 12 min · Medium

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which statement is used to execute a block of code only when a condition is true in C?

    • A. if
    • B. for
    • C. switch
    • D. goto
    Show answer

    A. if

    The if statement executes its associated statement or block when the specified condition evaluates to true.

  2. 2. Which statement is used to provide an alternative block when an if condition is false?

    • A. else
    • B. default
    • C. otherwise
    • D. alternate
    Show answer

    A. else

    The else statement provides an alternative block of code when the associated if condition is false.

  3. 3. Which statement is used to test multiple conditions sequentially in C?

    • A. else if
    • B. repeat if
    • C. case if
    • D. multiple if
    Show answer

    A. else if

    An else if statement allows multiple conditions to be checked in sequence.

  4. 4. Which C statement is commonly used to select one block of code from multiple alternatives based on an expression?

    • A. switch
    • B. select
    • C. choose
    • D. match
    Show answer

    A. switch

    The switch statement selects among multiple case labels based on the value of an integral or enumeration expression.

  5. 5. Which keyword is used to define an alternative case when no switch case matches?

    • A. default
    • B. else
    • C. otherwise
    • D. fallback
    Show answer

    A. default

    The default label in a switch statement is executed when none of the case labels matches the switch expression.

  6. 6. Which loop is generally used when the number of iterations is known or controlled by an initialization, condition, and update expression?

    • A. for
    • B. switch
    • C. if
    • D. goto
    Show answer

    A. for

    The for loop combines initialization, a controlling condition, and an iteration expression in its syntax.

  7. 7. Which loop checks its condition before executing the loop body?

    • A. while
    • B. do-while
    • C. repeat-until
    • D. foreach
    Show answer

    A. while

    A while loop evaluates its controlling expression before each iteration, so its body may execute zero times.

  8. 8. Which loop guarantees that its body executes at least once?

    • A. do-while
    • B. while
    • C. for
    • D. switch
    Show answer

    A. do-while

    A do-while loop executes its body before testing the condition, so the body runs at least once.

  9. 9. Which keyword immediately terminates the nearest enclosing loop or switch statement?

    • A. break
    • B. exit
    • C. stop
    • D. terminate
    Show answer

    A. break

    The break statement terminates execution of the nearest enclosing loop or switch statement.

  10. 10. Which keyword skips the remaining statements in the current loop iteration and proceeds to the next iteration?

    • A. continue
    • B. skip
    • C. next
    • D. pass
    Show answer

    A. continue

    The continue statement skips the remainder of the current loop body and continues with the next iteration.

  11. 11. What is the purpose of the goto statement in C?

    • A. To transfer control to a labeled statement
    • B. To repeat a loop automatically
    • C. To terminate the entire program
    • D. To declare a function
    Show answer

    A. To transfer control to a labeled statement

    The goto statement transfers execution directly to a statement identified by a label within the same function.

  12. 12. What will be printed by the following code? int x = 5; if (x > 3) printf("Yes"); else printf("No");

    • A. Yes
    • B. No
    • C. YesNo
    • D. Nothing
    Show answer

    A. Yes

    Since x is 5 and 5 > 3 is true, the statement inside the if branch prints Yes.

  13. 13. What happens when a break statement is encountered inside a switch case?

    • A. Execution exits the switch statement
    • B. The next case is always executed
    • C. The entire program terminates
    • D. The switch expression is evaluated again
    Show answer

    A. Execution exits the switch statement

    A break statement exits the nearest enclosing switch statement. Without break, execution can continue into subsequent cases.

  14. 14. What is the output of the following code? int i; for (i = 0; i < 3; i++) printf("%d ", i);

    • A. 0 1 2
    • B. 1 2 3
    • C. 0 1 2 3
    • D. 3 2 1
    Show answer

    A. 0 1 2

    The loop starts at 0 and continues while i is less than 3, producing 0, 1, and 2.

  15. 15. Which type of control structure is represented by an if-else statement?

    • A. Selection
    • B. Iteration
    • C. Function declaration
    • D. Preprocessing
    Show answer

    A. Selection

    An if-else statement is a selection control structure because it chooses which block of code to execute based on a condition.