21.
MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
21. (C++) Templates
What is the purpose of the "typename" and "template" keywords in template parameters?
Pick ONE option
Show answer & explanation
In C++ templates, "typename" (or "class") declares a type template parameter in the template declaration, while "template" is used to declare template template parameters—parameters that accept other templates. Option A correctly distinguishes their roles: typename declares parameters, and template is needed when passing templates as arguments.
Step-by-step Derivation:
Consider template declarations: 'template