AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 21 - 30 of 174 questions

21

Select the relevant output for the following set of code:

staticvoid Main(string[] args)

{

    int a =4;

    int b =5;

    int c =6;

    int d =8;

    if(((a * b / c)+ d)>=((b * c + d )/ a))

    {

        Console.WriteLine("Line 1 - a is greater to b");

        Console.WriteLine((a * b / c)+ d);

     }

    else

    {

        Console.WriteLine("Line 1 - a is not greater to b");

        Console.WriteLine((b * c + d )/ a);

     }

}

 

a

“Line 1 – a is greater to b”
11

b

“Line 1 – a is not greater to b”
9

c

Both are equal

d

None of the mentioned

correct answer a

Now, here in ‘if’ condition both conditions of parenthesis and hence evaluating operators based on parenthesis are tested.
for expression : ((a * b / c) + d)
Step 1 : (a*b/c) (Evaluating as 4*5/6 = 3)
Step 2 : ( (a*b/c) + d ) (Evaluating (3 + 8 = 11))
Result : 11
for expression : (b * c + d )/ a
Step 1 : (b*c + d) (Evaluating as 5*6 +8 = 38)
Step 2: (b*c + d) / a (Evaluating as 38 / 4 = 9)
Result : 9
The relational operator “>=” between both expressions check for largest figure and hence consecutively executes the if condition.
Output : Line 1 – a is greater to b.
11

22

Storage location used by computer memory to store data for usage by an application is ?

a

Pointers

b

Constant

c

Variables

d

None of the mentioned

correct answer c

‘Variables’ are essential locations in memory of computer that are reserved for storing data used by an application. Each variable is given a name by programmer and hence assigned a value .The name assigned to variable then used in C# code to access value assigned to variable.

23

Are the given codes :

1.   Myclass class;

     Myclass class2 = null;

2.   int i;

     int j = 0;

 

a

True for (1);False for (2)

b

True for (2);False for (1)

c

Both (1) and (2) are equivalents

d

Both (1) and (2) are not equivalents

correct answer c

When we create a type in ‘C#’, It automatically gets filled with padded zeroes. For the case of class (reference types) this equates to a null pointer. Hence, for code 1) Both variable values are equivalent to each other.Similarly, for code 2) i.e for value type (including int/float/double etc.), the type is passed with zeroes.Hence, they are equivalent.

24

What will be output of the following code?

staticvoid Main(string[] args)

{

     char a ='A';

     string b ="a";

     Console.WriteLine(Convert.ToInt32(a));

     Console.WriteLine(Convert.ToInt32(Convert.Tochar(b)));

     Console.ReadLine()

}

 

 

 

a

1, 97

b

55, 97

c

65, 97

d

97, 1

correct answer c

ASCII value of character ‘a’ is 65 and ASCII value of string “a” is 97.
Output: 65,97

25

Select output for the following set of code:

staticvoid Main(string[] args)

{

    constint a =5;

     const int b = 6;

     for(int i =1; i <=5; i++)

     {

     a = a * i;

     b = b * i;

     }

     Console.WriteLine(a);

     Console.WriteLine(b);

     Console.ReadLine();

}

 

 

a

600, 720

b

Compile time error

c

25, 30

d

5, 6

correct answer b

The left hand side of an assignment must be a variable,property or indexer i.e for both ‘a’ and ‘b’

26

Select output for the following set of code:

staticvoid Main(string[] args)

{

     string Name ="He is playing in a ground.";

     char[] characters = Name.ToCharArray();

     StringBuilder sb =new StringBuilder();

     for(int i = Name.Length-1; i >=0;--i)

     {

     sb.Append(characters[i]);

     }

     Console.Write(sb.ToString());

     Console.ReadLine();

}

 

 

a

He is playing in a grou

b

.ground a in playing is He

c

.dnuorg a ni gniyalp si eH

d

He playing a

correct answer c

Reversal of array of strings character by character.
Output: .dnuorg a ni gniyalp si eH

27

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

28

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.

29

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.

30

Type of Conversion in which compiler is unable to convert the datatype implicitly is ?

a

ushort to long

b

int to uint

c

ushort to long

d

byte to decimal

correct answer b

‘int’ is 32 bit signed integer whereas ‘uint’ is 32 bit unsigned integer .Range of int is larger than uint.So,compiler cannot implicitly convert from larger datatype to smaller datatype.

Select a company to compare with

vs

Similar Companies