define用法集.docVIP

  • 9
  • 0
  • 约5.84千字
  • 约 7页
  • 2016-12-09 发布于重庆
  • 举报
define用法集

Definition:The #define Directive   You can use the #define directive to give a meaningful name to a constant in your program. The two forms of the syntax are:   Syntax   #define identifier token-stringopt   #define identifier[ identifieropt, ... , identifieropt ] token-stringoptUsage:1.简单的define定义 #define MAXTIME 1000 一个简单的MAXTIME就定义好了,它代表1000,如果在程序里面写 ifimaxtime......... 编译器在处理这个代码之前会对MAXTIME进行处理替换为1000。 这样的定义看起来类似于普通的常量定义CONST,但也有着不同,因为define的定义更像是简单的文本替换,而不是作为一个量来使用,这个问题在下面反映的尤为突出。 2.define的“函数定义” define可以像函数那样接受一些参数,如下 #define maxx,y xy?x:y; 这个定义就将返回两个数中较大的那个,看到了吗?因为这个“函数”没有类型检查,就好像一个函数模板似

文档评论(0)

1亿VIP精品文档

相关文档