C语言宏定义与动态内存编程实例

32、编写一个程序,定义一个任意的宏,名为 MY_CONDITIONAL_MACRO。基于已存在和不存在的宏进行条件编译。使用 #define、#ifdef 和 #endif 指令。

#include <stdio.h>
#define MY_CONDITIONAL_MACRO

int main(void) {
#ifdef MY_CONDITIONAL_MACRO
    printf("This code will get compiled.\n");
#endif

#ifdef NON_EXISTING_MACRO
    printf("This code will not get compiled.\n");
#endif

    return 0;
}

33、编写一个使用内置宏名称的程序。该程序应输出语句的行号、文件名、文件创建日期、被调用函数的名称以及当前使用的 C 标准。

#include <stdio.h>

void myfunction() {
    printf("The name of the function called is: %s\n", __func__);
}

int main(void) {
    printf("This statement is on line: %d\n", __LINE__);
    printf("The name of the source file is: %s\n", __FILE__);
    printf("The file was created on: %s\n", __DATE__);
    myfunction();
    printf("The C standard used is: %ld\n", __STDC_VERSION__);
    return 0;
}

34、编写一个程序,定义两个类函数宏。第一个宏接受两个参数,并返回两个值中较小的那个。第二个宏也接受两个参数,并返回两个参数中较大的那个。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值