Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of code macros in C language

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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))

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report