C# Programming - Control Instructions
Exercise : Control Instructions - General Questions
- Control Instructions - General Questions
6.
What will be the output of the C#.NET code snippet given below?
int val;
for (val = -5; val <= 5; val++)
{
switch (val)
{
case 0:
Console.Write ("India");
break;
}
if (val > 0)
Console.Write ("B");
else if (val < 0)
Console.Write ("X");
}
7.
What will be the output of the C#.NET code snippet given below?
char ch = Convert.ToChar ('a' | 'b' | 'c');
switch (ch)
{
case 'A':
case 'a':
Console.WriteLine ("case A | case a");
break;
case 'B':
case 'b':
Console.WriteLine ("case B | case b");
break;
case 'C':
case 'c':
case 'D':
case 'd':
Console.WriteLine ("case D | case d");
break;
}
8.
Which of the following is the incorrect form of Decision Control instruction?
9.
Which of the following code snippets are the correct way to determine whether a is Odd or Even?
int a; String res; if (a % 2 == 0) res = "Even"; else res = "Odd";
int a; String res; if (a Mod 2 == 0) res = "Even"; else res = "Odd";
int a; Console.WriteLine(a Mod 2 == 0 ? "Even": "Odd");
int a; String res; a % 2 == 0 ? res = "Even" : res = "Odd"; Console.WriteLine(res);
10.
Which of the following can be used to terminate a while loop and transfer control outside the loop?
- exit while
- continue
- exit statement
- break
- goto
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers