int a =1 , b=2;
a=chg(b) ;
cout << a << b ;
If the function chg is coded as
int chg(int &x)
{
x = 10;
return ();
}
then Functions
A. | it results in compile-time error |
B. | it results in run time error |
C. | it prints 112 |
D. | it prints 111 0 |
Option: D Explanation : Here the parameter passing mechanism is pass by reference. Any change done to the parameter will be reflected outside the function. So, the value of b, after the exit of the function will be 10. Click on Discuss to view users comments. |
int a =1 , b=2;
a=chg(b) ;
cout << a << b ;
If the function chg is coded as
int chg(const int &x)
{
x=10;
return ()
};
then Functions
A. | it results in compile-time error |
B. | it results in run time error |
C. | it prints 112 |
D. | it prints 111 0 |
Option: A Explanation : Here the function chg tries to change the parameter x, which is not allowed as it is declared to be a constant integer. So, the compiler gives an error. Click on Discuss to view users comments. |
Which of the following parameter passing mechanism(s) is/are supported by C++, but not by C?
A. | Pass by value |
B. | Pass by reference |
C. | Pass by value-result |
D. | All of the above |
Option: B Explanation : As such C does not support pass by reference. But it can be simulated by using pointers. Click on Discuss to view users comments. |
If a piece of code can be implemented as a macro or as an inline function, which of the following factors favour implementation as an inline function?
A. | Interacting with other components (like variables in an expression), in the correct way .. |
B. | Flexibility to manipulate as a pointer |
C. | Source code size |
D. | Both (a) & (b) |
Option: D Explanation :
Macros do not have an address associated with them as they are processed by the pre-processor. Click on Discuss to view users comments. |
Assume that the random number generating function - rand( ), returns an integer between 0 and 10000 (both inclusive). If you want to simulate the throwing of a die using this random function, use the expression
A. | rand ( ) % 6 |
B. | rand ( ) % 6 + 1 |
C. | rand ( ) % 5 + 1 |
D. | none of the above |
Option: B Explanation : It should randomly generate any integer between 1 and 6. rand( ) % 6 returns an integer from 0 to 5. To make it 1 to 6, we need to add 1 Click on Discuss to view users comments. |
Syllabus covered in this section is-
This Section covers OOPS Questions Answers .These questions can be used for the preparation of various competitive and academic exams like
Who can benefit
Various Search Terms Used For This Section Are