ADVERTISEMENT
ADVERTISEMENT

Define Macros for YES and NO constants using #define in C | C preprocessor programs

Here, we are going to learn how to define macros – In this example, we are defining two Macros YES and NO by using #define preprocessor directive.
Submitted by IncludeHelp, on August 29, 2018

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.

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

C Preprocessors Programs »


ADVERTISEMENT




ADVERTISEMENT


Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.