LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 135|回复: 0

C++ #define 预处理器

[复制链接]
发表于 2024-1-12 16:46:13 | 显示全部楼层 |阅读模式
下面是使用 #define 预处理器定义常量的形式:

#define identifier value
具体请看下面的实例:

#include <iostream>
using namespace std;

#define LENGTH 10   
#define WIDTH  5
#define NEWLINE '\n'

int main()
{

   int area;  

   area = LENGTH * WIDTH;
   cout << area;
   cout << NEWLINE;
   return 0;
}
当上面的代码被编译和执行时,它会产生下列结果:

50

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表