1.定义顺序的无关性

  #define PI 3.14

  #define TWO_PI  2*PI

  这两句谁前谁后无所谓,因为预处理器不断迭代来实现宏替换,直到源文件中没有宏了才停止。

2. 宏变量变成字符串

   #define str(x)  #x  

   例子:str (teststring)  ==> "teststring"

3. 宏变量拼接

  #define print(n)  printf("%d\n",x##n)

  例子:print(20) ==> printf("%d\n",x20)

4. 定义长字符串如何换行

  #define url  "http://www.baidu.com" \

        "?hello=world&ni=hao"

  注意编译器会把两个相邻的字符串连接到一起,形成单个字符串。

相关文章:

  • 2021-07-18
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2022-02-09
  • 2021-06-27
猜你喜欢
  • 2021-10-28
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-09-03
  • 2021-12-02
相关资源
相似解决方案