AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 5 of 5 questions

1

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();

}

 

 

 

a

Rahul Dravid

b

Sachin Tendulkar

c

MS Dhoni

d

Warning : Unrechable code

correct answer b

(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

2

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);

     Console.ReadLine();

}

 

a

if ((num % 2) == 0)

{

even += 1;

}

else

{

odd += 1;

}

b

if((num * i) == 0)
{
even += 1;
}
else
{
odd += 1;
}

c

if(num[i] % 2 == 0)
{
even += 1;
}
else
{
odd += 1;
}

d

if(num[i] % 2 = 0)
{
even += 1;
}
else
{
odd += 1;
}

correct answer c

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()

3

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");

     }

     else

     {

     Console.WriteLine("In else");

     }

     Console.WriteLine("In main");

     Console.ReadLine();

}

 

a

In if

b

In else

c

In if

In main

d

In else

In main

correct answer d

Usage of ‘=’ operator instead of ‘==’ operator .hence,the condition is not true.
Output: In else
In main

4

Select the output for the following set of Code :

staticvoid Main(string[] args)

{

     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;

     else;

     else;

}

 

 

a

Compile time error: Misplaced else

b

Compile time error: Undefined symbol

c

java

d

Warning: Condition is always true

correct answer c

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.

5

Select the output for the following set of Code :

staticvoid Main(string[] args)

{

     int a =5, b =10;

     if(Convert.ToBoolean(Convert.ToInt32(++a))||Convert.ToBoolean(Convert.ToInt32(++b)))

     {

     Console.WriteLine(a +"\n"+ b);

     }

     else

     Console.WriteLine(" C# ");

}

 

a

6, 11

b

6, 16

c

6, 12

d

6, 10

correct answer d

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.

Select a company to compare with

vs

Similar Companies