Professional Documents
Culture Documents
This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on
“Default Arguments”.
View Answer
Answer: b
Explanation: 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.
advertisement
2. 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 rst in the argument list
c) Those can be de ned anywhere in the argument list
d) Those are declared inside the function de nition
View Answer
Answer: a
Explanation: 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 rst.
3. 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
View Answer
Answer: d
Explanation: 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.
View Answer
Answer: c
Explanation: 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.
5. If a function have all the default arguments but still some values are passed to the function then
______________
a) The function will use the values passed to it
b) The function will use the default values as those are local
c) The function can use any value whichever is higher
d) The function will choose the minimum values
View Answer
Answer: a
Explanation: The function will use the values passed explicitly to it. The default values will be ignored. The
default values are used only in case the values are not passed explicitly to the function.
advertisement
View Answer
Answer: c
Explanation: 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.
View Answer
Answer: d
Explanation: 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.
8. 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);
View Answer
Answer: c
Explanation: 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
View Answer
Answer: a
Explanation: 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.
advertisement
10. Which among the following is false for default arguments?
a) Those are not allowed with a declaration of pointer to functions
b) Those are not allowed with the reference to functions
c) Those are not allowed with the typedef declarations
d) Those are allowed with pointer and reference to function declaration
View Answer
Answer: d
Explanation: The statements given are true because that is a feature given to make the programming more
exible and have some security with accidental changes at same time. The last option is false because it is
not a rule de ned. It is an opposite statement to the rules de ned for default arguments.
11. The non-template functions can be added with default arguments to already declared functions
____________________
a) If and only if the function is declared again in the same scope
b) If and only if the function is declared only once in the same scope
c) If and only if the function is declared in di erent scope
d) If and only if the function is declared twice in the program
View Answer
Answer: a
Explanation: The non-template functions can also be added with default arguments. This can be done even if
the functions were de ned earlier. This is because the call to the function won’t be a ected. The function can
still be used in the same way as it was used earlier.
View Answer
Answer: b
Explanation: The using-declaration carries over all the known default arguments. This is a common feature
as the usage doesn’t gets a ected even if the default arguments are added. This comes under exible
programming.
13. The names given to the default arguments are only looked up and ________________ and are bound during
declaration.
a) Checked for availability
b) Checked for random access
c) Checked for accessibility
d) Checked for feasibility
View Answer
Answer: c
Explanation: The names given to the default arguments are bound at time of declaration but are only
checked for accessibility and to get bounded. This is mainly to bind those members during declaration.
advertisement
View Answer
Answer: d
Explanation: The default argument are bound at the time of declaration. That is an implicit functioning. But
those are executed only when the function is called. Otherwise, those will never get executed.
Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).
To practice all areas of Object Oriented Programming (OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.
Participate in the Sanfoundry Certi cation contest to get free Certi cate of Merit. Join our social networks
below and stay updated with latest contests, videos, internships and jobs!
advertisement
Recommended Posts:
1. C Programming Examples on Linked List
2. Java Programming Examples
3. C Programming Examples on Stacks & Queues
4. Simple C Programs
5. C Tutorials
6. C Programming Examples
7. R Programming Questions and Answers
8. C++ Programming Examples on Data-Structures
9. C# Programming Examples on Arrays
10. C Programming Examples on Arrays
11. C Programming Examples on Strings
12. Java Programming Examples on Inheritance
13. Ruby Programming Questions and Answers
14. C# Programming Examples on Functions
15. C Programming Examples on Searching and Sorting
16. C++ Questions and Answers
17. C Programming Examples on File Handling
18. Java Programming Examples on File Handling
19. Java Programming Examples on Classes
20. Object Oriented Programming Questions and Answers
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and
CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about
competency developments in these areas. He lives in Bangalore and delivers focused
training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers,
Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies,
SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him
@ LinkedIn
Name*
Email*
Subscribe
About | Certi cations | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact