wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Conditional Statements in C

Total questions: 16

Worksheet time: 8mins

Name
Class
Date
1.

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?

a)

It executes a block of code only if the condition evaluates to true.

b)

It always executes the block of code regardless of the condition.

c)

It executes a block of code only if the condition evaluates to false.

d)

It does not execute any code.

2.

Fill in the blank: The if-else statement in C provides an alternative block of code to execute if the condition evaluates to _____

a)

false

b)

true

c)

zero

d)

positive

3.

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?

a)

x is less than or equal to 5

b)

x is greater than 5

c)

Nothing will be printed

d)

Error

4.

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?

a)

x is greater than 5

b)

x is less than or equal to 5

c)

Nothing will be printed

d)

Error

5.

What is the purpose of the else if ladder in programming?

a)

To execute one block of code out of many options based on the value of an expression

b)

To test multiple conditions sequentially and execute the corresponding block when a condition is true

c)

To repeat a block of code multiple times

d)

To define a function

6.

Fill in the blank: In an else if ladder, once a condition evaluates to ______, the corresponding block is executed and the rest are skipped.

a)

true

b)

false

c)

zero

d)

null

7.

What will be printed when the code is executed?

a)

x is equal to 15

b)

x is equal to 10

c)

x is equal to 5

d)

No output will be printed

8.

What is the purpose of the switch statement in programming?

a)

To test multiple conditions sequentially

b)

To execute one block of code out of many options based on the value of an expression

c)

To repeat a block of code multiple times

d)

To define a variable

9.

Fill in the blank: In a switch statement, the ______ block is executed if no case matches the value of the expression.

a)

default

b)

case

c)

break

d)

continue

10.

Which statement is used for simple conditions?

a)

if

b)

if-else

c)

else if

d)

switch

11.

Which statement is used when there are two possible outcomes?

a)

if

b)

if-else

c)

else if

d)

switch

12.

Which statement is used for multiple conditions?

a)

if

b)

if-else

c)

else if

d)

switch

13.

Which statement is ideal for handling multiple discrete values of a variable?

a)

if

b)

if-else

c)

else if

d)

switch

14.

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"); }

a)

y is less than 10

b)

y is 10 or more

c)

Error

d)

No output will be printed

15.

Which statement is used to handle multiple conditions in a more readable way than nested if statements?

a)

if

b)

if-else

c)

else if

d)

switch

16.

Fill in the blank: The ______ statement allows for a default case to be executed if no other cases match in a switch statement.

a)

continue

b)

default

c)

case

d)

break