Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
static void Main(string[] args)
{
float f;
for (f = 0.1f; f <= 0.5; f += 1)
Console.WriteLine( ++f );
Console.ReadLine();
}

What will be the output of the following C# code?
static void Main(string[] args)
{
float f;
for (f = 0.1f; f <= 0.5; f += 1)
Console.WriteLine( ++f );
Console.ReadLine();
}
a) 1.1
b) 0.1
c) 0.1 0.2 0.3 0.4 0.5
d) None of the mentioned

Answer: a
Explanation: f = 0.1 and ++f = 0.1+1 = 1.1. So, 1.1>0.5, Condition fails and hence loop terminates.

Join The Discussion