This is an interview test question not homework. The test has been done.
Which of the following statements about default arguments in C++ are correct ?
A. Default Argument cannot be of a user-defined type.
B. Default Argument can never precede non-default arguments
C. Default Argument cannot be of pointer type.
D. Default Argument exist in global heap not function's stack
E. Default Argument are not considered for generating the function's signature.
I chose B and E. Are these correct? I am not sure about D, is that correct too?
B is true. A, C and D are false.
E requires clarification. It depends on what is meant by "generating the function's signature".
As far as the compiler is concerned, the signature is the signature. Default arguments only matter when calling the function. That's where the defaults are substituted in. So the function has the signature it is written with.
If "generating the function's signature" means "what is the C++ signature of the function is", then the signature doesn't care whether an argument is default. But if "generating the function's signature" means "how you call it", then it does care about the defaults.
A, C, and D are all definitely false. B is definitely true. I'm not so sure about E, I always forget.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With