Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of code macros in C language

Shulou Source: shulou.com Published: 2022-06-03 09:23:35 11月03日 Update

This article will explain in detail what is the use of code macros in C language. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1. Define the macro # define ARRAY_SIZE 100double data [array _ SIZE]

As shown in the following figure, the above code replaces the ARRAY_SIZE in the code with 100 when the compiler makes a macro replacement

2. Macro function

There is no concept of any type of argument to a macro function, so

The macro function is used as follows, and the MAX (3. 4) in the code is replaced with the expression defined by the macro.

# define MAX (a) b) a > b? A: bint N1 = MAX (3penny 4)

Be careful

The error in the above replacement is because the parameter to the macro function is passed an expression, and you can use the following method

Do not pass the expression for the parameters of the macro function, as shown in the following figure, the expression has been operated twice

3. Multi-line macros

Use a slash to connect the next line of code, suitable for macros with long code

# define IS_HEX_CHARACTOR (ch)\ ((ch) > ='0' & & (ch) ='A'& & (ch) ='a' & & (ch))

Tags: Code functions parameters expressions articles languages more good practical one line following figure example content as is variables differences articles slashes methods concepts Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS Docker Redmi MariaDB