Search Placementyogi.com
 

C# Control Instructions - Advanced Objective Questions

1

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    public class ForLoop
    {
        public static void Main(string[] args)
        {
            int i;
            for (i = 1; i++ <= 5; Console.WriteLine(i))
            Console.Write("Inside the loop : ");
        }
    }
}
A.

Inside the loop: 2

Inside the loop: 3

Inside the loop: 4

Inside the loop: 5

Inside the loop: 6

B.

Inside the loop: 1

Inside the loop: 2

Inside the loop: 3

Inside the loop: 4

Inside the loop: 5

C.

2 Inside the loop:

3 Inside the loop:

4 Inside the loop:

5 Inside the loop:

6 Inside the loop:

D.

1 Inside the loop:

2 Inside the loop:

3 Inside the loop:

4 Inside the loop:

5 Inside the loop:

See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

Step 1. At first i is initialized to 1.

Step 2: Now the condition i++ < 5 is checked, Here i is currently 1 and the value is incremented only after use.

So,The condition is TRUE and the Console.Write statement("Inside the loop : ") is executed.

Step 3: The control then enters the increment section of for loop, it contains -> Console.WriteLine(i).

The value of i had been incremented earlier in the condition section and hence 2 is printed.

Thus, when i = 2 next time and condition i++ <= 5 is TRUE, 3 is printed.

This goes on till last time when i = 5 as i++ would still be less than and equal to 5 and 6 is printed.

Next time i is 6 and 6++ <=5 is FALSE and the loop exits.

 
2

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    public class Loop
    {
        public static void Main(string[] args)
        {
            int i = 24;
            for ( ; ; )
            {
                Console.Write(i + " ");
                if (i >= -8)
                    i -= 8;
                else
                    break;
            }
        }
    }
}
A.

24 16 8

B.

24 16 8 0

C.

24 16 8 0 -8

D.

24 16 8 0 -8 -16

E.

None of these

See Answer & Explanation Lets Discuss
Correct answer is : D
Explanation

No explanation available. Let's Discuss

 
3

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    public class Loop
    {
        public static void Main(string[] args)
        {
            int i;
            for (i = -4; i <= 4; i++)
            {
                switch (i)
                {
                    case 0:
                        Console.Write("~");
                        break;
                }
                if (i > 0)
                    Console.Write("R");
                else if (i < 0)
                    Console.Write("L");
            }
        }
    }
}
A.

LL~RR

B.

LLL~RRR

C.

LLLL~RRRR

D.

LLLLL~RRRRR

E.

None of these

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

No explanation available. Let's Discuss

 
4

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    public class Loop
    {
        public static void Main(string[] args)
        {
            char c = Convert.ToChar('a' | 'b' | 'c');
            Console.Write(c);
            switch (c)
            {
                case 'a':
                    Console.WriteLine("case a");
                    break;
                case 'b':
                    Console.WriteLine("case b");
                    break;
                case 'c':
                case 'd':
                    Console.WriteLine("case c | case d");
                    break;
                default: Console.WriteLine("no case"); break;
            }
        }
    }
}
A.

case a

B.

case b

C.

case c | case d

D.

no case

E.

None of these

See Answer & Explanation Lets Discuss
Correct answer is : D
Explanation

If you perform bitwise | (OR) operation on the ASCII values of 'a','b','c','d' and convert the resultant to char then g comes which fall into the default case hence no case is printed.

 
 

Banner to LogicGuns.com

Hide Page Information

C# Control Instructions - Advanced Objective Questions and Answers

Here you can find advanced level C# Control Instructions (for, while, do-while, switch, if-else) interview questions with answers and explanation.

Why Control Instructions in C#.NET?

In this section you can learn and practice different types of advanced level questions with answers on Control Instructions to improve your skills in order to face the interviews, competitive examinations and various entrance tests with full confidence.

Where can I get C# Control Instructions Advanced Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved advanced level Control Instructions questions and answers with explanation. Fully solved examples with detailed answer description and explanation are given and it would be easy to understand. All students, freshers can download Control Instructions quiz questions with answers as PDF files and eBooks.

Where can I get Advanced Level C# Control Instructions Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type advanced Control Instructions questions and answers for interview and entrance examination. Multiple choice and TRUE or FALSE type and YES or NO type questions are also provided.