c语言 预处理
  nw5Goo4OC4L7 2023年11月02日 37 0
extern 引用外部全局变量



#define SIZE 20

int a[SIZE]; //经常这么用



宏替换

#define Print(My_var) printf(" %d",My_var)

#define max(x,y) x>y?x:y



如果一行放不下可以加 \ 换行继续





字符串作为宏参数



#define STR "cxc"



用宏连接字符串

#define join(a,b) a##b

printf("%d\n", strlen(join("cxc","as")));//输出5



#ifndef block 等价于 #if !define block

#ifdef block 等价于 #if defined block



条件宏举例:

#include<stdio.h>

#include<string.h>



#define A 0

#define B 1

#define C A



#if A == B

#define STR "相等"

#else

#define STR "不相等"

#endif

int main(void)

{

printf("%s\n",STR );

return 0;

}




日期宏



#include<stdio.h>

#include<string.h>



int main(void)

{

char date[] = __DATE__;

printf("%s %s\n",date,__TIME__ );

return 0;

}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  4WdcduV19eWs   2023年11月02日   64   0   0 ios#includeios#include
  4WdcduV19eWs   2023年11月02日   62   0   0 ios#includeios#include
  4WdcduV19eWs   2023年11月02日   66   0   0 ios#includeios#include
  4WdcduV19eWs   2023年11月02日   53   0   0 ios#includeios#include
  4WdcduV19eWs   2023年11月02日   42   0   0 ios#includeios#include
  4WdcduV19eWs   2023年11月02日   65   0   0 ios#includeios#include
  4WdcduV19eWs   2023年11月02日   87   0   0 ios#includeios#include
  WNX8ZrUuErM5   2023年11月02日   34   0   0 #if客户端#endif
  4WdcduV19eWs   2023年11月02日   49   0   0 ios#includeios#include
  4WdcduV19eWs   2023年11月02日   78   0   0 #includelinuxlinux#include
nw5Goo4OC4L7
作者其他文章 更多

2023-11-02