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
A. | rand ( ) % (b-a) |
B. | (rand ( ) % a) + b |
C. | (rand( ) % (b-a)) + a |
D. | (rand( ) % (b-a+l)) + a |
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. Click on Discuss to view users comments. |
Which of the following decides if a function that is declared inline is indeed going to be treated inline in the executable code?
A. | Compiler |
B. | Linker |
C. | Loader |
D. | Preprocessor |
Option: A Explanation : Click on Discuss to view users comments. |
Which of the following type of functions is an ideal candidate for being declared inline?
A. | A function that is small and is not called frequently. |
B. | A function that is small and is called frequently. |
C. | A function that is not small and is not called frequently. |
D. | A function that is not small and is called frequently. |
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. Click on Discuss to view users comments. |
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
A. | passing pointers |
B. | declaring the formal parameters constant |
C. | declaring the actual parameters constant |
D. | all of the above |
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. Click on Discuss to view users comments. |