Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

If-Else Statements Practice Set 1

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What will be the output of the following code? int x = 5; if (x > 4) printf("A"); if (x > 6) printf("B"); else printf("C");

a)

A

b)

ABC

c)

AC

d)

C

2.

Which of the following is TRUE about if statement in C?

a)

Condition must be float

b)

Condition must be Boolean

c)

Condition must be integer

d)

Curly braces are compulsory

3.

What will be the output? int a = 0; if (a = 5) printf("Yes"); else printf("No");

a)

Error

b)

Undefined

c)

No

d)

Yes

4.

default case in switch is:

a)

Mandatory

b)

Optional

c)

Must be first

d)

Must be last

5.

How many times will the loop execute? int i; for(i = 0; i < 10; i += 3);

a)

0

b)

3

c)

Infinite

d)

Error

6.

What is the output? int i = 1; while(i <= 5) { printf("%d ", i); i += 2; } A. 1 2 3 4 5 B. 1 3 5 C. 2 4 D. Infinite loop

a)

1 3 5

b)

Infinite loop

c)

1 2 3 4 5

d)

2 4

7.

Difference between while and do-while loop is:

a)

None

b)

do-while executes at least once

c)

Both same

d)

while executes at least once

8.

What will be the output? int i = 0; for(; i < 3; ) printf("%d ", i++);

a)

0 1 2

b)

Error

c)

Infinite

d)

1 2 3

9.

switch statement internally works like:

a)

recursion

b)

loop

c)

if-else ladder

d)

macro

10.

What is the output? int x = 5; if(x = 0) printf("A"); else printf("B");

a)

Runtime error

b)

A

c)

Compilation error

d)

B

11.

Which of the following is TRUE about if statements?

a)

Nested if is allowed

b)

if cannot be used without else

c)

else is mandatory

d)

Multiple else blocks are allowed

12.

What is the output? int a = 10; if(a > 5) if(a < 15) printf("X"); else printf("Y");

a)

X

b)

Y

c)

Compilation error

d)

No output

13.

default case in switch is:

a)

Mandatory

b)

Must be last

c)

Must be first

d)

Optional

14.

How many times will the loop execute? int i = 1; while(i <= 10) { i = i * 2; }

a)

Infinite

b)

4

c)

3

d)

2

15.

What is the output? int i = 0; do { printf("%d ", i); i++; } while(i < 0);

a)

Compilation error

b)

Infinite

c)

No output

d)

0

16.

break statement is used to:

a)

Exit loop or switch

b)

Skip current iteration

c)

Terminate program

d)

Pause execution

17.

What is the output? int i = 5; if(i = 10) printf("YES"); else printf("NO");

a)

YES

b)

NO

c)

Error

d)

Depends on compiler

18.

Which loop is guaranteed to execute at least once?

a)

while

b)

do-while

c)

infinite loop

d)

for

19.

Which of the following causes an infinite loop?

a)

for(;;)

b)

while(1)

c)

do { } while(1);

d)

All of the above

20.

Which statement is TRUE?

a)

switch supports float values

b)

break is mandatory in switch

c)

case labels must be constants

d)

switch can use relational expressions