ACtE03 · Chapter 3Programming & Applications🏛️ Past Licensure QuestionID: 0c625a36
Which statement regarding C++ templates versus preprocessor macros is incorrect?
Which statement regarding C++ templates versus preprocessor macros is incorrect?
Multiple Choice Options
- A✓ Correct Option
Macros are more efficient than templates
- B
Templates provide type safety
- C
Macros can lead to code bloat
- D
Templates are resolved at compile time
Detailed Technical Solution & Explanation
In modern C++, templates are resolved at compile time with strong type checking, inlining, and compiler optimization, generating code that is just as fast as or faster than macros. Preprocessor macros simply perform naive textual substitution without type safety, leading to operator precedence bugs, multiple evaluations of side-effect arguments, and difficult debugging.
Option Analysis:
•
Option A (Macros are more efficient than templates): Correct (this statement is false/incorrect). Modern compilers optimize templates to have zero runtime overhead relative to macros while ensuring strict type safety.
•
Option B (Templates provide type safety): True statement. The compiler enforces strict type checking on template parameters.
•
Option C (Macros can lead to code bloat): True statement. Multiple textual expansions cause code bloat.
•
Option D (Templates are resolved at compile time): True statement. Template instantiation occurs entirely during compilation.
Reference: Demo2 · Set 1NEC Licensure Syllabus