Object Oriented Programming - Functions

11. Assume that the random number generating function - rand( ), returns an integer between 0 and 10000 (both inclusive). To randomly generate a number between a and b (both inclusive), use the expression

  • Option : D
  • Explanation : An example will help you understand. Let a be 6 and b be 10. There are 5 numbers between 6 to 10 (both inclusive). This is b-a+ 1 (10 - 6 + 1). rand( ) % (b - a + 1) returns an integer from 0 to (b - a). To make it a to b, add a, giving rand() % (b-a+ 1) + a.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


12. Which of the following decides if a function that is declared inline is indeed going to be treated inline in the executable code?

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


13. Which of the following type of functions is an ideal candidate for being declared inline?

  • Option : B
  • Explanation : If the function is small, it is not going to significantly increase the code size. If it is made inline, there is no function call overhead. How much you gain is proportional to the frequency of call.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


14. One of the disadvantages of pass-by reference is that the called function may inadvertently corrupt the caller's data. This can be avoided by

  • Option : B
  • Explanation : If the formal parameters are declared constants, the compiler will not allow any changes to be made. So the question of inadvertently corrupting the caller's data, does not arise at all.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


15. Choose the best answer.
A function that does the same operation on different data types is to be implemented using

Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *