Macros with Arguments

Learn how macros can be used with arguments in a manner similar to function calls.

We can use #define directives to create macros in more advanced ways, such as by including an expression or code statements in the body of a macro. We can also use parameters with the macro name, which allows us to use it much the same way we would use a function.

A first example

For example, we could define a macro to perform the square of a number like this:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy