NEW
Font size
WorksheetsOperators_Control Structures
Total questions: 10
Worksheet time: 5mins
Debug the code: What will be printed? int a = 5; if (a = 10 > 5) { Console.WriteLine("Hello"); }
Hello
No output
Compile-time error
Runtime error
What is the output? int x = 1; x = x++ + ++x; Console.WriteLine(x);
2
3
4
5
What does this print?
int i = 0;
while(i < 3) {
if(i == 1) break;
Console.Write(i);
i++;
}
0
01
012
No output
Predict the output int a = 10; if(a > 5) if(a < 20) console.Write("A"); else console.Write("B"); else console.Write("C");
A
B
C
Compiler error
Debug: What happens?
switch(2) {
case 1: Console.Write("A");
case 2: Console.Write("B");
case 3: Console.Write("C");
break;
}
ABC
BC
B
Compile error
Predict output int a = 5, b = 10; Console.WriteLine(a > 3 && ++b > 10); Console.WriteLine(b);
false, 10
true, 11
true, 10
false, 11
Debug: What happens?
for(int i = 0; i < 3; i++) {
Console.Write(i);
i++;
}
012
02
01
0
Predict output
int x = 0;
do {
x++;
if (x == 2)
Continue;
Console.Write(x);
} while (x < 4);
1234
134
234
13
Debug the code
bool flag = false;
if(flag = true) Console.Write("OK");
else Console.Write("NO");
OK
NO
Compiler error
Runtime error
What is the output? int a = 2; int b = 3; Console.WriteLine(a > b ? a++ : ++b); Console.WriteLine(a + " " + b);
2, 3 4
3, 2 3
3, 2 4
4, 2 4
