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
What is the output of the following code?
static void Main(string[] args)
{
int a = 5 ;
if(Convert.ToBoolean((.002f)-(0.1f)))
Console.WriteLine("Sachin Tendulkar");
elseif(a ==5)
Console.WriteLine("Rahul Dravid");
else
Console.WriteLine("Ms Dhoni");
Console.ReadLine();
}
Rahul Dravid
Sachin Tendulkar
MS Dhoni
Warning : Unrechable code
(0.002 – 0.1f) not equivalent to zero hence it is true. So,only first if clause will execute and print:Sachin Tendulkar on console.As,first condition is always true so no else if statement will be executed. Output: Sachin Tendulkar
Select the correct ‘if statement’ to be filled in the given set of code :
static void Main(string [] args)
int[]num ={50, 65, 56, 88, 43, 52};
int even =0, odd =0;
for(int i =0;i < num.Length;i++)
/*_________________*/
Console.WriteLine("Even Numbers:"+even);
Console.WriteLine("Odd Numbers:"+odd);
if ((num % 2) == 0)
even += 1;
odd += 1;
if((num * i) == 0) { even += 1; } else { odd += 1; }
if(num[i] % 2 == 0) { even += 1; } else { odd += 1; }
if(num[i] % 2 = 0) { even += 1; } else { odd += 1; }
int []num = {50, 65, 56, 88, 43, 52}; int even = 0,odd = 0; for (int i = 0 ;i < num.Length ;i++) { if (num[i] % 2 == 0) { even += 1; } else { odd += 1; } } Console.WriteLine("Even Numbers: " +even); Console.WriteLine("Odd Numbers: " +odd); Console.ReadLine()
Select the output for the following set of code :
staticvoid Main(string[] args)
int i =30;
int j =25%25;
if(Convert.ToBoolean(Convert.ToInt32(i = j)))
Console.WriteLine("In if");
Console.WriteLine("In else");
Console.WriteLine("In main");
In if
In else
In main
Usage of ‘=’ operator instead of ‘==’ operator .hence,the condition is not true. Output: In else In main
Select the output for the following set of Code :
int a =5, b =10;
if(Convert.ToBoolean(Convert.ToInt32(0xB)))
if(Convert.ToBoolean(Convert.ToInt32(022)))
if(Convert.ToBoolean(Convert.ToInt32('\xeb')))
Console.WriteLine("java");
else;
Compile time error: Misplaced else
Compile time error: Undefined symbol
java
Warning: Condition is always true
oxB: hexadecimal integer constant. 022: It octal integer constant. ‘\xeb’: It is hexadecimal character constant. As,zero is false and any non-zero number is true. All,constants return a non-zero value. So, all if conditions in the above program are true. Output: java.
if(Convert.ToBoolean(Convert.ToInt32(++a))||Convert.ToBoolean(Convert.ToInt32(++b)))
Console.WriteLine(a +"\n"+ b);
Console.WriteLine(" C# ");
6, 11
6, 16
6, 12
6, 10
Consider the following expression:( ++a || ++b). In this expression || is ‘Logical OR operator’. Two important properties of this operator are: Property 1: (Expression1) || (Expression2) || operator returns 0 if and only if both expressions return a zero otherwise || operator returns 1. initial value of a is 5. So ++a will be 6. Since ++a is returning a non-zero so ++b will not execute. Output : 6 10.
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