AmbitionBox
Discover Best Places to work in India
Discover best places to work
Compare & find best workplace
Bring your workplace to life
Highlight your company's perks
Read reviews for 6L+ companies
Rate your former or current company
Discover salaries for 8L+ companies
Calculate your take home salary
Check your market value
Help other jobseekers
Read interviews for 90K+ companies
Interviews questions for 1K+ colleges
Contribute your interview questions
C# Programming
Select the output for the following set of code:
staticvoid Main(string[] args)
{
float s = 0.1f;
while(s <= 0.5f)
++s;
Console.WriteLine(s);
}
Console.ReadLine();
0.1
1.1
0.1 0.2 0.3 0.4 0.5
No output
for the first while condition check when s = 0. If it is true as control goes inside loop ++s increments value of s by 1 as 1+0.1 = 1.1. So, for next condition while loop fails and hence, prints final value of s as 1.1. Output: 1.1
Select the output for the following set of code :
int i, j;
for(i =1; i <=3; i++)
j =1;
while(i % j ==2)
j++;
Console.WriteLine(i +" "+ j);
11 21 31
1 12 13 1
1 1 2 1 3 1
Since, condition never satisfied for any value of i and j for which (i % j == 2).Hence, j is always constant ‘1’ and ‘i’ increments for i = 1, 2, 3. Output: 11 21 31.
Select the output for the following set of Code:
int i;
i =0;
while(i++<5)
Console.WriteLine(i);
Console.WriteLine("\n");
while(++i <5)
1 2 3 4 1 2 3 4 5
1 2 3 1 2 3 4
1 2 3 4 5 1 2 3 4
1 2 3 4 5 1 2 3 4 5
for while(i++ < 5) current value of 'i' is checked first and hence prints incremented value afterwards.So, i =1, 2, 3, 4, 5.But, for while(++i < 5) current value is incremented first and then checks that value with given condition and hence then prints that value.So, i = 1, 2, 3, 4. Output: 1 2 3 4 5 1 2 3 4
Join India’s largest community to research company culture
Are you a student or working professional?
Student/Never worked
I am a student/I have never worked
Working Professional
I am working/I have worked before
What are your preferred job locations?
Popular Cities
Other Cities
Follow your preferred designations/job profiles
Suggestions based on your job profile
vs
Similar Companies