NEW
Font size
WorksheetsConditional Statements in C
Total questions: 16
Worksheet time: 8mins
Conditional statements in C are used to make decisions based on certain conditions. Which of the following statements is true about the if statement in C?
It executes a block of code only if the condition evaluates to true.
It always executes the block of code regardless of the condition.
It executes a block of code only if the condition evaluates to false.
It does not execute any code.
Fill in the blank: The if-else statement in C provides an alternative block of code to execute if the condition evaluates to _____
false
true
zero
positive
Given the following code example: int x = 10; if (x > 5) { printf("x is greater than 5\n"); } What will be printed when this code is executed?
x is less than or equal to 5
x is greater than 5
Nothing will be printed
Error
Given the following code example: int x = 3; if (x > 5) { printf("x is greater than 5\n"); } else { printf("x is less than or equal to 5\n"); } What will be printed when this code is executed?
x is greater than 5
x is less than or equal to 5
Nothing will be printed
Error
What is the purpose of the else if ladder in programming?
To execute one block of code out of many options based on the value of an expression
To test multiple conditions sequentially and execute the corresponding block when a condition is true
To repeat a block of code multiple times
To define a function
Fill in the blank: In an else if ladder, once a condition evaluates to ______, the corresponding block is executed and the rest are skipped.
true
false
zero
null
What will be printed when the code is executed?
x is equal to 15
x is equal to 10
x is equal to 5
No output will be printed
What is the purpose of the switch statement in programming?
To test multiple conditions sequentially
To execute one block of code out of many options based on the value of an expression
To repeat a block of code multiple times
To define a variable
Fill in the blank: In a switch statement, the ______ block is executed if no case matches the value of the expression.
default
case
break
continue
Which statement is used for simple conditions?
if
if-else
else if
switch
Which statement is used when there are two possible outcomes?
if
if-else
else if
switch
Which statement is used for multiple conditions?
if
if-else
else if
switch
Which statement is ideal for handling multiple discrete values of a variable?
if
if-else
else if
switch
What will be the output of the following code? int y = 7; if (y < 10) { printf("y is less than 10\n"); } else { printf("y is 10 or more\n"); }
y is less than 10
y is 10 or more
Error
No output will be printed
Which statement is used to handle multiple conditions in a more readable way than nested if statements?
if
if-else
else if
switch
Fill in the blank: The ______ statement allows for a default case to be executed if no other cases match in a switch statement.
continue
default
case
break
