AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 6 of 6 questions

1

Which of these will happen if recursive method does not have a base case?

a

infinite loop condition occurrence

b

System gets hanged

c

After 10000 executions program will be automatically stopped.

d

None of the mentioned

correct answer a

If a recursive method does not have a base case which is necessary to meet the end of condition then an infinite loop occurs which results in stackoverflow exception error.

2

What is Recursion in CSharp defined as?

a

Recursion is another form of class

b

Recursion is another process of defining a method that calls other methods repeatedly

c

Recursion is a process of defining a method that calls itself repeatedly

d

Recursion is a process of defining a method that calls other methods which in turn calls this method

correct answer c

Recursion is the process of defining something in terms of itself. It allows us to define method that calls itself repeatedly until it meets some base case condition.

3

Which of these is not a correct statement?

a

A recursive method must have a base case

b

Recursion always uses stack

c

Recursion is always managed by C# Runtime environment

d

Recursive methods are faster that programmer written loop to call the function repeatedly using a stack

correct answer c

No matter whatever is the programming language recursion is always managed by operating system.

4

Which of these data types is used by operating system to manage the Recursion in Csharp?

a

Array

b

Queue

c

Tree

d

Stack

correct answer d

Answer: Option (D)

5

What will be the correct output the for the given code snippet?

class maths

{

     int fact(int n)

     {

          int result;

          if(n ==1)

          return1;

          result = fact(n -1)* n;

          return result;

     }

}

class Output

{

     staticvoid main(String args[])

     {

          maths obj =new maths();

          Console.WriteLine(obj.fact(1));

     }

}

 

 

 

 

 

 

 

a

2

b

10

c

1

d

0

correct answer c

fact() calculates recursively the factorial of a number when n turns to be 1, base case is executed consecutively and hence 1 is returned.
Output: 1

6

What will be the correct output for the given code snippet?

class maths

{

     int fact(int n)

     {

          int result;

          if(n ==1)

          return1;

          result = fact(n -1)* n;

          return result;

     }

}

class Output

{

      staticvoid main(String args[])

     {

          maths obj =new maths();

          Console.WriteLine(obj.fact(4)*(3));

     }

}

 

 

 

 

 

a

64

b

60

c

72

d

84

correct answer c

4! = 4 * 3 *2 * 1 = 24 * 3 = 72.Not factorial of 3 but just multiply the number with 3.
Output : 72

Select a company to compare with

vs

Similar Companies