Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on Control Structures

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the syntax of an if statement in C?

a)

if condition { /* code to execute */ }

b)

if (condition) /* code to execute */ }

c)

if { condition } { /* code to execute */ }

d)

if (condition) { /* code to execute */ }

2.

How does a switch case statement work in C?

a)

A switch case statement evaluates an expression and executes code based on matching case labels.

b)

A switch case statement only works with integer values.

c)

A switch case statement can only have one case label.

d)

A switch case statement requires a loop to function properly.

3.

What is the purpose of a for loop in C?

a)

To define a function in C

b)

To handle errors in C

c)

To create a new variable in C

d)

The purpose of a for loop in C is to facilitate repeated execution of a block of code for a defined number of iterations.

4.

How do you declare a while loop in C?

a)

for(condition) { // code to execute }

b)

while(condition) { // code to execute }

c)

repeat(condition) { // code to execute }

d)

do while(condition) { // code to execute }

5.

What is the difference between a while loop and a do-while loop?

a)

A while loop is used for infinite loops, while a do-while loop is not.

b)

A while loop executes at least once, while a do-while loop may not execute at all.

c)

Both loops execute the same number of times regardless of the condition.

d)

The main difference is that a while loop may not execute at all if the condition is false, while a do-while loop always executes at least once.

6.

Can you nest if statements in C? Provide an example.

a)

C does not support conditional statements

b)

Example: if (condition1) { if (condition2) { // code to execute if both condition1 and condition2 are true } }

c)

if statements cannot be nested in C

d)

You can only use one if statement at a time

7.

What is the syntax for a conditional operator in C?

a)

condition ? value_if_false : value_if_true

b)

condition : value_if_true ? value_if_false

c)

condition ? value_if_true : value_if_false

d)

if(condition) value_if_true else value_if_false

8.

How do you write an if-else statement in C?

a)

if { /* code */ } else (condition) { /* code */ }

b)

if (condition) { /* code */ } else { /* code */ }

c)

if (condition) { /* code */ } else: { /* code */ }

d)

if condition { /* code */ } else { /* code */ }

9.

What happens if no case matches in a switch statement?

a)

The switch statement will throw an error if no case matches.

b)

The switch statement will loop back to the first case if no case matches.

c)

The switch statement will execute the default case if no case matches.

d)

The switch statement will exit without executing any case code if no case matches.

10.

How can you use a break statement in a loop?

a)

You can use a break statement to pause the loop temporarily.

b)

You can use a break statement to continue looping indefinitely.

c)

You can use a break statement in a loop to exit the loop when a specific condition is met.

d)

A break statement is used to skip the current iteration of the loop.

11.

What is the output of the following code:

for(int i=0; i<5; i++)

{

printf("%d ", i);

}

a)

1 2 3 4 5

b)

0 1 2 3

c)

0 1 2 3 4 5

d)

0 1 2 3 4

12.

Explain the use of the continue statement in loops.

a)

The continue statement pauses the loop for a specified time.

b)

The continue statement restarts the loop from the beginning.

c)

The continue statement skips the current iteration of a loop and moves to the next iteration.

d)

The continue statement ends the loop immediately.

13.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

double k = 0;

for (k = 0.0; k < 3.0; k++)

printf("Hello");

}

a)

Run time error

b)

Hello is printed thrice

c)

Hello is printed twice

d)

Hello is printed infinitely

14.

How can you combine multiple conditions in an if statement?

a)

Use '&&' for 'and' and '||' for 'or' to combine conditions.

b)

Use '==' for 'and' and '!=' for 'or' to combine conditions.

c)

Combine conditions by using commas in the if statement.

d)

Use 'and' and 'or' keywords directly in the if statement.

15.

Find the output:

#include <stdio.h>

void main()

{

int ch;

printf("enter a value between 1 to 2:");

scanf("%d", &ch);

switch (ch)

{

case 1:

printf("1\n");

default:

printf("2\n");

}

}

a)

1

b)

2

c)

1 2

d)

Run time error