宏定義(用宏定義寫一個求最大值)和條件編譯

#define _CRT_NO_SECURE_WARNING
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define max2(a,b) (a)>(b)? (a):(b)
#define max3(a,b,c) (a)> (max2(b,c))?(a):(max2(b,c))
#define D1

int main()
{         //條件編譯一共三種
#ifdef D1//1.條件編譯(預處理做的)2. 如果是#ifndef 就是測試不存在 3.#if
    printf("D1\n");
#else
    printf("other\n");
#endif
//
#ifndef _D2_H_ //_D2_H_ 自定義宏,每個頭文件的宏不一樣
    #define _D                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         2_H_ 
#else
    printf("other\n");
#endif
//
# if 1
        printf("TEST");
#else
        printf("NO");
#endif
    printf("%d\n",max2(1,2));
    printf("%d\n", max3(1, 2,3));
    system("pause");
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章