Skip to main content

Functional Macros in C

A function-like macro (also called a parameterised macro) accepts arguments and expands them inline — like a function, but done at the preprocessor stage before compilation. They are faster than function calls because there is no function call overhead.

Syntax

Always wrap the entire expression and each parameter in parentheses to avoid operator precedence bugs.

Examples

Square of a number:
Maximum of two numbers:
Minimum of two numbers:
Absolute value:

Complete Program

Output:

Why Parentheses Matter

Without parentheses around parameters, expressions involving operators can produce wrong results:
Always parenthesise both the parameters and the full expression.

Macros vs Functions

Use macros for short, frequently-called operations. Prefer inline functions in C99+ for type safety.