动态 版块 发帖 消息 我的
Loading...
小绿叶技术博客
小绿叶技术博客
小绿叶技术Lv153   
c 语言 define ifdef endif c 宏的使用     


#include<stdio.h>
#define MAX
#define MAXIMUM(x,y)(x>y)?x:y
#define MINIMUM(x,y) (x>y)?y:x        // 理解为: if ( x > y ) return y; else return x;   
                                      // 符号() 判断 ;   问号 ? 条件成立(then) 返回y的值;  冒号 : 条件不成立(else) 返回x


int main()
{
    int a=10,b=20;
#ifdef MAX
    printf("已经使用define 定义 MAX 宏 条件成立, 当前板块代码有效  %d\n",MAXIMUM(a,b));
#else
    printf("没有定义 MAX 当前板块代码无效 %d\n",MINIMUM(a,b));
#endif
// endif 结束判断 宏




#ifndef MIN
    printf("ifndef 判断没有定义弘(多了一个n), 条件成立,该板块代码有效 MIN %d\n", MINIMUM(a,b));
#else
    printf("已经定义 MIN 宏, 该板块代码无效 %d\n",MAXIMUM(a,b));
#endif




#undef MAX                  // 取消之前定义的 宏
#ifdef MAX
    printf("定义有效 %d\n",MAXIMUM(a,b));
#else
    // else 否则
    printf("定义的 MAX 宏 被 undef 取消定义,当前等于没有定义 MAX 宏 %d\n",MINIMUM(a,b));
#endif

    return 0;
}




 1  已被阅读了434次  楼主 2023-03-09 14:30:55
回复列表

回复: c 语言 define ifdef endif c 宏的使用

guest
登录之后更精彩~
Powered by HadSky 7.12.10
© 2015-2023 PuYueTian
您的IP:8.219.134.200,2023-10-04 00:56:11,Processed in 0.02856 second(s).
Powered by HadSky
小绿叶技术博客