c语言define常量定义_在C |中使用#define为YES和NO常量定义宏。 C预处理程序

c语言define常量定义

In this example, we have to define two macros YES with the constant value 1 and NO with the constant value 0 by using #define preprocessor directive in C programming language.

在此示例中,我们必须使用C编程语言中的#define预处理程序指令来定义两个常量值为1的宏YES和0常量为0NO

Macros definitions:

宏定义:

    #define	YES	1
    #define	NO	0

Example:

例:

#include <stdio.h>

#define	YES	1
#define NO	0

//function to check and return YES or NO
//for EVEN or ODD
int checkEvenODD(int num)
{
	if( num%2 == 0 )
		return YES;
	else
		return NO;
}

//Main code
int main(){
	
	int n;
	
	n = 10;
	if( checkEvenODD(n) == YES )
		printf("%d is an EVEN number\n",n);
	else
		printf("%d is an ODD number\n",n);

	n = 11;
	if( checkEvenODD(n) == YES )
		printf("%d is an EVEN number\n",n);
	else
		printf("%d is an ODD number\n",n);	
	
	return 0;
}

Output

输出量

    10 is an EVEN number
    11 is an ODD number

翻译自: https://www.includehelp.com/c-programs/define-macros-for-YES-and-NO-constants-using-define.aspx

c语言define常量定义

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值