wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Decision and Case Control Statements in C

Total questions: 35

Worksheet time: 18mins

Name
Class
Date
1.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

int x = 5;

if (x < 1)

printf("hello");

if (x == 5)

printf("hi");

else

printf("no");

}

a)

hi

b)

hello

c)

no

d)

error

2.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int x = 0;

if (x == 1)

if (x == 0)

printf("inside if\n");

else

printf("inside else if\n");

else

printf("inside else\n");

}

a)

inside if

b)

inside else if

c)

inside else

d)

compile time error

3.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int x = 0;

if (x == 1)

if (x >= 0)

printf("true\n");

else

printf("false\n");

}

a)

Depends on the compiler

b)

No print statement

c)

True

d)

False

4.

The output of the following segment is

int k, n=20;

k=(n>5?(n<=10?100:200):500);

printf("%d",n);

a)

100

b)

200

c)

300

d)

20

5.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = 1, b = 1;

switch (a)

{

case a*b:

printf("yes ");

case a-b:

printf("no\n");

break;

}

}

a)

yes

b)

no

c)

yes no

d)

compile time error

6.

What is the result after execution of the following code if a is 10, b is 5, and c is 10?

if ((a > b) && (a <= c))

a = a + 1;

else

c = c+1;

a)

a = 10, c = 10

b)

a = 11, c = 10

c)

a = 10, c = 11

d)

a = 11, c = 11

7.

Output of the following code


#include <stdio.h>

int main()

{ int i = 0;

switch (i)

{

case '0': printf("Geeks");

break;

case '1': printf("Quiz");

break;

default: printf("GeeksQuiz");

}

return 0;

}

a)

Geeks

b)

Quiz

c)

GeeksQuiz

d)

None of the above

8.

How will you print \n on the screen?

a)

printf("\n");

b)

echo "\\n";

c)

printf('\n');

d)

printf("\\n");

9.

int main()

{

if(0);

printf("Hello");

printf("Hi");

return 0;

}

a)

Hi

b)

Hello

c)

HelloHi

d)

Compilation Error

10.

what is output of following code?


#include <stdio.h>

int main( )

{

if(printf("C programming is"))

{

printf("Easy");

}

else

{

printf("Hard");

}

return 0;

}

a)

C Programming Easy

b)

Easy

c)

Hard

d)

None of these

11.

Find Error/ output in following code

Void main ()

{

int a= 1, b= 2, c = 3;

Char d = 0;

if (a,b,c,d)

{

printf ( " EXAM") ;

}

}

a)

No output and No error

b)

EXAM

c)

Runtime Error

d)

Compile time error

12.

Find Error/ output in following code

Void main ()

{

printf ( " % d " , printf ( " computer science"));

}

a)

Computer science16

b)

16computer science

c)

Computer science

d)

Computer science18

13.

What will be the output of the program?

int main ()

{

printf ( 5+"Good Morning\n");

return 0;

}

a)

Good Morning

b)

Good

c)

M

d)

Morning

14.

What happens to the code in the body of an "if" statement if the condition is false?

a)

The computer determines if it is essential to the program and if it is, then the code is executed anyway.

b)

The code moves to a coastal city, attempting to find love and start a family. However, low waged and crushing mortgage rates lead to it moving back home where it sits, hoping that one day it will be executed.

c)

The code is skipped.

d)

The code stages a revolution and attempts to take over the program, ultimately unsuccessfully, which leads to it not being executed.

15.

what is the ouput of the below program?


int main()

{

int i=10, j=20;

if((i=100) && (j==20))

{

printf("Have a nice day");

}

else

{

printf("condition not true");

}


return 0;

}

a)

No output

b)

Have a nice day

c)

condition not true

d)

Complier Error

16.

What is the output ?

int var;

var = !(0 && (2||1));

printf("%d",var);

a)

0

b)

2

c)

1

d)

Compiler Error

17.
We want to round off x, a float, to an int value, The correct way to do is
a)
y = (int)(x + 0.5)
b)
y = int(x + 0.5)
c)
y = (int)x + 0.5
d)
y = (int)((int)x + 0.5)
18.
a)

Char 65

b)

Integer 65

c)

Bye

d)

Compilation Error

19.
a)

Bye

b)

Integer

c)

Char

d)

Compilation Error

20.
a)

case 2 executed

b)

case 1 executed

c)

default block executed

d)

Compilation Error

21.
a)

case 1 executed

b)

case 1 executed case 2 executed

c)

case 2 executed

d)

Compilation Error

22.
a)

Compilation Error

b)

case 1 executed

c)

case 2 executed

d)

default block executed

23.
a)

Switch ON the fan

b)

Switch ON the Air Cooler

c)

Save Energy

d)

Compilation Error

24.
a)

First

b)

Bye

c)

Second

d)

Compilation Error

25.
a)

Hai. This is case 3

b)

Hai. This is case 6

c)

Infinite Execution

d)

Hai. This is default

26.
a)

25L

b)

25.0

c)

Compilation Error

d)

Nothing

27.
a)

case one

b)

case two

c)

default block

d)

Compile Time Error

28.
a)

inside default

b)

FALSE

c)

TRUE

d)

Compilation Error

29.
a)

inside case

b)

inside default

c)

Prints Nothing

d)

Compilation Error

30.
a)

inside case 1

b)

inside case 3

c)

inside case 4

d)

inside case 7

31.
a)

inside case 1

b)

inside case 3

c)

inside case 4

d)

inside case 7

32.
a)

Hai. This is case 0 Hai. This is case 1

b)

Hai. This is case 0 Hai. This is case 2

c)

Hai. This is case 0 Hai. This is case 1 Hai. This is case 2

d)

Hai. This is case 0 Hai. This is default

33.
a)

Runtime Error

b)

Hai default

c)

Compilation Error

d)

Hai default Hai case 1 Hai case 2 Hai case 3

34.

What does the following code fragment write to the monitor?

a)

Under

b)

Over

c)

Under the limit

d)

Over the limit

35.

What does the following code fragment write to the monitor?

a)

Under

b)

Over

c)

Under the limit

d)

Over the limit