Does the default argument in C ++ have some special properties?

This is an interview test question, not a homework assignment. The test has been completed.

Which of the following statements about default arguments in C ++ is 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 stack E. Default Argument are not considered for generating the function signature. 

I chose B and E. Are they correct? I'm not sure about D, is that correct too?

+4
source share
2 answers

B is true. A, C and D are false.

E requires clarification. It depends on what is meant by “generating a function signature”.

As for the compiler, a signature is a signature. Arguments by default only matter when the function is called. Where the default values ​​are replaced. Thus, the function has a signature with which it is written.

If “generating a function signature” means “what is a C ++ signature for a function”, then the signature does not care if the argument is the default value. But if "generating a function signature" means "as you call it," then it takes care of the default values.

+7
source

A, C, and D are all false. B is definitely true. I am not sure about E, I always forget.

+2
source

Source: https://habr.com/ru/post/1380971/


All Articles