close

#include(檔 入)

-- def.h 的檔案內容 --
 
         #define PI  3.14159
         #define a   10
         #define b   20

 

#include < stdio.h >
  #include "def.h"
  
main()
  {
            printf("PI=%2.5f\n",PI);
            printf("a+b=%d\n",a+b);
 }
執行結果 :
 
             PI=3.14159
             a+b=30

 

 

 

  #define(字 / 義)與 #undef

#define 巨集名稱 常數或函式或字串

example:

#include < stdio.h >

#define  compare(a,b)      \

if ( a > b )        \
printf("a > b");  \
else                \
if ( a < b )      \
printf("a < b");\
else              \
printf("a = b");
 
    
 
void main(void) 
{
int a,b; 
a=5;  
b=10; 
compare
(a,b);
}
   
執行結果 : a < b




























 

arrow
arrow
    全站熱搜

    tear2001 發表在 痞客邦 留言(0) 人氣()