Difficulty: Easy
Correct Answer: Correct
Explanation:
Introduction / Context:
Function-like macros are a core feature of the C preprocessor. They accept arguments and substitute tokens before compilation. This question confirms familiarity with parameterized macros and their implications.
Given Data / Assumptions:
Concept / Approach:
Function-like macros are defined as #define NAME(arg1, arg2, ...) replacement. During preprocessing, the arguments in a macro invocation are substituted into the replacement list and the result is compiled as ordinary C code. They are widely used for small inline-like substitutions, constants, and conditional wrappers.
Step-by-Step Solution:
Recall syntax: #define SQR(x) ((x)(x))
.Invoke as SQR(3+1)
→ expands to ((3+1)(3+1))
.Hence, parameterized macros are indeed permitted.
Verification / Alternative check:
Compile a trivial program using such a macro and observe the generated code or preprocessor output.
Why Other Options Are Wrong:
Incorrect — contradicts the language. Allowed only in C++ — false; C and C++ both support them. Allowed only with #pragma — unrelated.
Common Pitfalls:
Forgetting parentheses around parameters and the result; side effects like SQR(i++)
duplicating increments; macros lacking type safety compared to inline functions.
Final Answer:
Correct
Discussion & Comments