C preprocessor – are macros with arguments permitted? Decide whether parameterized (function-like) macros are allowed in standard C.

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:

  • The claim: “Macros with arguments are allowed.”
  • Standard C preprocessing is assumed.

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

More Questions from C Preprocessor

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion