Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Select the output for the following set of code?

  1. static void Main(string[] args)
  2. {
  3. int i = 5;
  4. for (; Convert.ToBoolean(Convert.ToInt(i)); Console.WriteLine(i--)) ;
  5. Console.ReadLine();
  6. }

a)b)c)1d)

user-image
Question added by Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
Date Posted: 2016/10/20

Output : 5

               4

               3

               2

               1

 

Explanation: Initial value of i is 5 , the "i" value will be converted as boolean and going to check the condition with that boolean value.,as the iteration part is concerned it displays the values of  "i" and decrement it's counter  until i becomes 0 then loop will terminate.

 

mohammed hussamuddin hussamuddin
by mohammed hussamuddin hussamuddin , C Technical Lead , Infosys

Console.ReadLine will unable to read any data because the for condition check evaluate to false initially so no out put.

More Questions Like This