1. What happens when you compile and run the below program?
|
public class Program
{
public static void Main(string[] args)
{
char x = 'X';
int i = 0;
Console.WriteLine (true ? x : 0);
Console.WriteLine(false ? i : x);
}
}
|
Output:
88
88
2. Predict the output for below program.
|
public class Program
{
public static void Main(string[] args)
{
int x = 1975;
int y = 2015;
x ^= y ^= x ^= y;
Console.WriteLine("x = " + x + "; y = " + y);
}
}
|
Output:
x = 0;Y=1975
3. What will be the output for below program?
|
public class Program
{
public static bool isOdd(int i) {
return i % 2 == 1;
}
public static void Main(string[] args)
{
}
}
|
Output:
The program will be compiled successfully
4. Predict the output for below Program
|
public class Program
{
public static void Main(string[] args)
{
String letters = "ABC";
char[] numbers = { '1', '2', '3' };
Console.WriteLine(letters + " easy as " + numbers);
}
}
|
Output:
ABC easy as System.Char[]
5. What will be the output for below program?
|
public class Program
{
public static void Main(string[] args)
{
int i = 5;
int j = 6;
while (i <= j && j <= i && i != j) {
Console.WriteLine("Good Day !!");
}
}
}
|
Output:
The program will be compiled successfully with no output.
6. Predict the output for below Program.
|
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine ("iexplore:");
http://www.google.com;
Console.WriteLine(":maximize");
}
}
|
Output:
iexplore:
:maximize
7. What will be the output for below program?
|
public class Program
{
public static void Main(string[] args)
{
int i=5;
while (i != i + 0) {
Console.WriteLine("Hello");
}
}
}
|
Output:
The program will be compiled successfully with no output
8. Predict the Output for below program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public class Program
{
static void Main(string[] args)
{
work();
Console.WriteLine("Hello");
}
private static void work()
{
try
{
work();
}
finally
{
work();
}
}
}
|
Output:
StackOverflowException
9. What will be the output for below program?
1
2
3
4
5
6
7
8
9
10
11
12
|
public class Program
{
public static void Main(string[] args)
{
Program Puzzler = null;
Console.WriteLine(Program.get());
}
private static String get()
{
return "i am a C# puzzler";
}
}
|
Output:
i am a C# puzzler
10. Predict the output for below program?
|
public class Program
{
public static void Main(string[] args)
{
Double i = Double.NaN;
while (i != i)
{
Console.WriteLine("Hello");
}
}
}
|
Output:
It will be an infinite loop with ‘Hello’
0 Comments