1. What happens when you compile and run the below program?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class Program
{
public static void Main(string[] args)
{
int x = 0;
int y = 0;
for (short z = 0; z < 5; z++) { if ((++x > 3) || (++y > 3))
{
x++;
}
}
Console.WriteLine (x+ "" + y);
}
}
|
Output:
73
2. 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
21
|
public class Program
{
public static void Main(string[] args)
{
int i = 3;
int j;
method1(ref i);
method2(out j);
Console.WriteLine(i + " " + j);
}
static void method1(ref int x)
{
x = x + x;
}
static void method2(out int x)
{
x = 4;
x = x * x;
}
}
|
Output:
6 16
3. What will be the output for below program?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
public class Program
{
public static void Main(string[] args)
{
try
{
Console.WriteLine("Hello World !!");
Environment.Exit(0);
}
finally
{
Console.WriteLine("Goodbye World !!");
}
}
}
|
Output:
Hello World !!
4. Predict 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)
{
Boolean b1 = true, b2 = false;
if ((b1=false) |(b1^b2))
{
Console.WriteLine("success");
}
}
}
|
Output:
The program will be compiled successfully with no output
5. What will be the output for below program?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public class Program
{
public static void Main(string[] args)
{
string s1 = "fcwysaE";
string s2 = "fcwysae";
if (s1 == s2)
Console.WriteLine("Equal");
else
Console.WriteLine("Unequal");
if (s1.Equals(s2))
Console.WriteLine("Equal");
else
Console.WriteLine("Unequal");
Console.ReadLine();
}
}
|
Output:
Unequal
Unequal
6. Predict the output for below Program.
|
public class UnsafeCode
{
public unsafe static void Main()
{
int n = 10;
void* p = &n;
Console.WriteLine(*p);
Console.ReadLine();
}
}
|
Output:
This will give a compile time error
7. What will be 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
{
public static void Main(string[] args)
{
Console.WriteLine(waffle());
}
public static Boolean waffle()
{
Boolean A = false;
try
{
A = true;
return A;
}
finally
{
A = false;
}
}
}
|
Output:
True
8. Predict the Output for below program
|
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("H" + "a");
Console.WriteLine('H' + 'a');
}
}
|
Output:
Ha
169
9. What will be the output for below program?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class Program
{
public Program(Object o)
{
Console.WriteLine("Object");
}
public Program(double[] dArray)
{
Console.WriteLine("double array");
}
public static void Main(string[] args)
{
new Program(null);
}
}
|
Output:
double array
10. Predict 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)
{
for (byte b = Byte.MinValue;
b < Byte.MaxValue; b++)
{
if (b == 0x90)
Console.WriteLine("Welcome to Viastudy !! ");
}
}
}
|
Output:
Welcome to Viastudy!!
0 Comments