Redpine Infotech Placement: Sample Questions 4 - 5 of 19

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 4

Edit

Describe in Detail

Essay▾

Difference between re-entrance and recursion.

Explanation

Difference between Re-Entrance and Recursion
Re-entranceRecursion
A re-entrant function can be safely executed concurrently.A recursive function calls upon itself until a given condition is met
Re-entrant function does operations like protect/lock static state.Recursive functions do not need to protect/lock access static state.
Re-entrant function needs able to handle concurrent execution with different threads.Recursive able to handle entry while it is running, but it access controlled manner and not other thread.
Re-entrant recursive functions are thread-safe.Recursive functions are not thread-safe
Re-enter functions cannot modify static variablesRecursion functions can modify static variables.

Question 5

Question

MCQ▾

What is output for the following program?

  1. #include<stdio.h>
  2. main ()
  3. {
  4.     intn=2;
  5.     intsum=5;
  6.     switch (n)
  7.     {
  8.         case2:sum=sum-2;
  9.         case3:sum ⚹=5;
  10.         break;
  11.         default:sum=0;
  12.     }
  13.     printf (“%d” sum);
  14. }

Choices

Choice (4)

a.

6

b.

15

c.

0

d.

None of the above

Answer

b.

Explanation

Table Shows the Program
#include < tdio. h >Standard library function
main ()startup after initialization
int n = 2;

int sum = 5;

Declare integer value n = 2 and sum = 5
switch (n)Switch in n, n = 2, so switch (2)
case 2: sum = sum-2;

case 3: sum ⚹= 5;

In case: 2
  • Sum = sum-2, so, sum = 5 - 2 = 3
  • As there is no break after this case execution continues to next case.

In case: 3

  • Sum ⚹= 5, thus, sum = 3 ⚹ 5 = 15
  • so, sum = 15
break;Switch breaks and sum = 15
default: sum = 0;This statement is not checked
printf ( “% d” sum) ;Print sum = 15

Developed by: