Recursion and Iteration Interview Questions and Answers | Recursion Examples



1. What is the output of this C code ?

Function main() {
  integer a = 5, b = 7
  Switch(a) {
    Case 5: print "I am 5"
    Break
    Case b: print "I am not 5"
    Break
    Default: print "I am different"
  }
}

A. I am 5

B. I am not 5

C. I am different

D. Error

E. None of these

Answer : D. Error




2. Ashima wants to print a pattern which includes checking and changing a variables value iteratively She decides to use a loop/condition Which of the following options should she use such that the body of the loop/condition is executed at least once whether the variable satisfies the entering condition or not ?

A. For loop

B. While loop

C. Do-while loop

D. Switch case

E. None of these

Answer : C. Do-while loop




3. The construct “if (condition) then A else B” is used for which of the following purposes ?

A. Decision making

B. Iteration

C. Recursion

D. Object oriented programming

Answer : A. Decision making




4. Integer a = 40, b = 35, c = 20, d = 10
Comment about the output of the following two statements.
I . Print a*b/c-d
II . Print a*b/(c-d)

A. Differ by 80

B. Same

C. Differ by 50

D. Differ by 160



5. What is the output of the following pseudo code ?

Int a = 456, b, c, d = 10;
b = a / d;
c = a - b;
print c

A. 411.4

B. 411

C. 410.4

D. 410

E. None of these

Answer : B. 411




6. Ravi and Rupali are asked to write a program to sum the rows of 2X2 matrices stored in the array A.
Ravi writes the following code (Code A):

for n = 0 to 1 
sumRow1[n] = A[n][1] + A[n][2]
end

Rupali writes the following code (Code B):

sumRow1[0] = A[0][1] + A[0][2]
sumRow1[1] = A[1][1] + A[1][2]

Comment upon these codes (Assume no loop unrolling done by compiler) ?

A. Code a will execute faster than b.

B. Code b will execute faster than a.

C. Code a is logically incorrect.

D. Code b is logically incorrect

Answer : B. Code b will execute faster than a




7. What is the output of this C code ?

Function main() {
  Integer i = 0.7 Static float m = 0.7
  If(m equals i)
  Print(“We are equal”)
  Else
  If(m > i)
  Print(“I am greater”)
  Else
  Print(“I am lesser”)
}

A. We are equal.

B. I am greater.

C. I am lesser.

D. This code will generate an error.

Answer : D. This code will generate an error





Related Searches to Recursion and Iteration Interview Questions and Answers | Recursion Examples