Test Series - oops

Test Number 68/78

Q: What are default arguments?
A. Arguments which are not mandatory to be passed
B. Arguments with default value that aren’t mandatory to be passed
C. Arguments which are not passed to functions
D. Arguments which always take same data value
Solution: The arguments which are assigned with some default value. Since some value is already given, it is not mandatory to pass those arguments. They can be used directly.
Q: Which is the correct condition for the default arguments?
A. Those must be declared as last arguments in argument list
B. Those must be declared first in the argument list
C. Those can be defined anywhere in the argument list
D. Those are declared inside the function definition
Solution: The default arguments must be declared at last in the argument list. This is to ensure that the arguments doesn’t create ambiguity. The normal arguments should be passed first.
Q: If a member function have to be made both zero argument and parameterized constructor, which among the following can be the best option?
A. Two normal and one default argument
B. At least one default argument
C. Exactly one default argument
D. Make all the arguments default
Solution: All the arguments must be made default. This will make sure that none of the arguments are mandatory to be passed. Which in turn means that the function can work without any argument and can be passed with arguments too.
Q: Which among the following function can be called without arguments?
A. void add(int x, int y=0)
B. void add(int=0)
C. void add(int x=0, int y=0)
D. void add(char c)
Solution: For the function to be called without arguments, either it must have zero arguments or it must have all the default arguments. Here the function in option void add(int x=0, int y=0) have all the default arguments and hence can be called directly with zero argument.
Q: Which among the following is correct?
A. void test(int x=0, int y, int z=0)
B. void test(int x=0, int=0)
C. void test(int x, int y=0)
D. void test(int x=’c, int y)
Solution: The default arguments must be mentioned at last in the argument list. Also, the type of values assigned must match with the argument type. All the default arguments must be mentioned at last, none of the normal arguments should come in between the default arguments list.
Q: Which among the following is a wrong call to the function void test(int x, int y=0, int z=0)?
A. test(5,6,7);
B. test(5);
C. test();
D. test(5,6);
Solution: The function must be passed with at least one argument. There is two default arguments and one normal argument which must be passed with some value. Hence the third call to the function is wrong as it doesn’t pass even a single parameter to the function
Q: The using declaration __________
A. Doesn’t carry over the default values
B. Carries over the known default arguments
C. Carries over only the normal arguments
D. Carries over only few default arguments
Solution: The using-declaration carries over all the known default arguments. This is a common feature as the usage doesn’t gets affected even if the default arguments are added. This comes under flexible programming.
Q: What function will be called with the independent syntax “test(5,6,7);”?
A. void test(int x, int y)
B. void test(int x=0, int y, int z)
C. int test(int x=0, y=0, z=0)
D. void test(int x, int y, int z=0)
Solution: There are three arguments that are getting passed to the function test(). Only the last option have all the default argument at last in the argument list. And the total number of the arguments is three. The third option is wrong because the return type is int and the syntax given is independent which means it doesn’t return any value.
Q: Default arguments are _________________________
A. Only allowed in the parameter list of the function declaration
B. Only allowed in the return type of the function declaration
C. Only allowed with the class name definition
D. Only allowed with the integer type values
Solution: The default arguments are only allowed in the parameter list of the function arguments. This rule was not applicable in the beginning versions of c++ but later from c++ 14th version it has been implemented. This is the only way to use default arguments.
Q: The virtual function overrides ____________
A. Do not acquire base class declaration of default arguments
B. Do acquire base class declaration of default arguments
C. Do not link with the default arguments of base class
D. Do link with the default argument but only of derived classes
Solution: The virtual function overrides do not acquire the base class declaration of default arguments. Even if a call to the virtual function is made, static type of the object decides the default arguments to be used.

You Have Score    /10