C# Coding Interview Questions (Part – 8)

Datetime:2016-08-22 22:10:29          Topic: C#           Share

1. What will be the output for below program

 public static void Main(string[] args)
    {
        int x = 0;
        int y = 0;
 
        for (short z = 0; z < 3; z++)
        {
            if ((++x > 1) || (++y > 1))
            {
                x++;
            }
        }
        Console.WriteLine(x + "" + y);
    }

Output:

51

2. What will be the output for below program?

 public class Program
    {
        public static void Main(string[] args)
        {
            String s = "ONE" + 1 + 2 + "TWO" + "THREE" + 3 + 4 + "FOUR" + "FIVE" + 5;
            Console.WriteLine(s);
          
        }
        
    }

Output:

ONE12TWOTHREE34FOURFIVE5

3. What will be the output for below program?

    public class Program
    {
        public static void Main(string[] args)
        {
            int i = (byte)+(char)-(int)+(long)-1;
            Console.WriteLine(i);
        }
    }

Output:

1

4. Predict the output for below program

 public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(1); 
            http://csharpStar.com/
            Console.WriteLine(2);
 
        }
    }

Output:

1

2

5. Predict the output for below program

public class Program
    {
        public static void Main(string[] args)
        {
            int i = 13;
            int j = 14;
            i = --i - i--;
            j = ++j + j++;
            Console.WriteLine(i+j);
 
        }
    }

Output:

30

6. What will be the output for below program

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

7. What happens when you compile and run the below program?

 public class Program
    {
        public static void Main(string[] args)
        {
          int i = 10 + + 11 - - 12 + + 13 - - 14 + + 15;
                Console.WriteLine(i);
          
        }
    }

Output:

75

8. What will be the output for below program?

public class Program
{
    public static void Main(string[] args)
    {
        Boolean b1 = true, b2 = false;
        if ((b2 = true) | (b1 ^ b2))
        {
            Console.WriteLine("success");
        }
    }
 
}

Output:

success

9. will you get compile error for below program?

public class Program
{
    public static bool isOdd(int i)
    {
        return i % 2 == 0;
    }
 
    public static void Main(string[] args)
    {
 
    }
}

Output:

No, The program will be compiled successfully

10. What will be the output for below program?

class Program
{
    public static int i = 0;
    public static void Main()
    {
        (i++).Print();
    }
}
 
static class Extensions
{
    public static void Print(this int i)
    {
        Console.WriteLine(Program.i);
        Console.WriteLine(i);
    }
}

Output:

1

0

You may also Like:

C# Coding Interview Questions (Part – 1) C# Coding Interview Questions (Part – 2) C# Coding Interview Questions (Part – 3) C# Coding Interview Questions (Part – 4) C# Coding Interview Questions (Part – 5) C# Coding Interview Questions (Part – 6) C# Coding Interview Questions (Part – 7) C# Interview Questions for Experienced professionals (Part – 1) C# Interview Questions for Experienced professionals (Part – 2) C# Interview Questions for Experienced professionals (Part – 3) C# Interview Questions for Experienced professionals (Part – 4) C# Interview Questions for Experienced professionals (Part – 5) C# Interview Questions for Experienced professionals (Part – 6) C# Interview Questions for Experienced professionals (Part – 7) C# Interview Questions for Experienced professionals (Part – 8) C# Interview Questions for Experienced professionals (Part – 9)

Thanks for Visiting !!

© 2016,admin. All rights reserved.





About List