wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Operators_Control Structures

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Debug the code: What will be printed? int a = 5; if (a = 10 > 5) { Console.WriteLine("Hello"); }

a)

Hello

b)

No output

c)

Compile-time error

d)

Runtime error

2.

What is the output? int x = 1; x = x++ + ++x; Console.WriteLine(x);

a)

2

b)

3

c)

4

d)

5

3.

What does this print?

int i = 0;

while(i < 3) {

if(i == 1) break;

Console.Write(i);

i++;

}

a)

0

b)

01

c)

012

d)

No output

4.

Predict the output int a = 10; if(a > 5) if(a < 20) console.Write("A"); else console.Write("B"); else console.Write("C");

a)

A

b)

B

c)

C

d)

Compiler error

5.

Debug: What happens?

switch(2) {

case 1: Console.Write("A");

case 2: Console.Write("B");

case 3: Console.Write("C");

break;

}

a)

ABC

b)

BC

c)

B

d)

Compile error

6.

Predict output int a = 5, b = 10; Console.WriteLine(a > 3 && ++b > 10); Console.WriteLine(b);

a)

false, 10

b)

true, 11

c)

true, 10

d)

false, 11

7.

Debug: What happens?

for(int i = 0; i < 3; i++) {

Console.Write(i);

i++;

}

a)

012

b)

02

c)

01

d)

0

8.

Predict output

int x = 0;

do {

x++;

if (x == 2)

Continue;

Console.Write(x);

} while (x < 4);

a)

1234

b)

134

c)

234

d)

13

9.

Debug the code

bool flag = false;

if(flag = true) Console.Write("OK");

else Console.Write("NO");

a)

OK

b)

NO

c)

Compiler error

d)

Runtime error

10.

What is the output? int a = 2; int b = 3; Console.WriteLine(a > b ? a++ : ++b); Console.WriteLine(a + " " + b);

a)

2, 3 4

b)

3, 2 3

c)

3, 2 4

d)

4, 2 4