What is multiline macro?
How to write a multiline macro in C programming language. We typically define macros that span over a single line. However, there exist conditions whenever you need to outline a macro that spans over a number of lines.
In this put up I’ll clarify how to write a multiline macro in C language. So allow us to get began.
Required data
Basic C programming, Preprocessor directives, Macros
During the course of macros programming workout routines, we learned the fundamentals of macros. How to outline and undefine a macro. In this put up, we are going to continue forward with macro and will be taught to define a multiline macro.
For a lot of the instances, macros are candy and short, prolonged up to a single line. However, typically we outline difficult macros that span over a number of traces. Defining these macros in a single line will lose code readability, therefore we outline multiline macro.
Read extra How to print the supply code of a program?
To define a multiline macro append lash on the finish of every line of a macro.
Program to define a multiline macro in C
#include <stdio.h>
// Macro to check and print even odd number
#define EVEN_ODD(num) \
if (num & 1) \
printf("%d is odd\n", num); \
else \
printf("%d is even\n", num);
int main()
{
int num;
// Input number from user
printf("Enter any number: ");
scanf("%d", &num);
EVEN_ODD(num);
return 0;
}
Note: The last line of the macro should not comprise \ symbol
Enter any quantity: 11 11 is odd
C Programming Recommended Post
- Introduction to C Programming – Setup CodeBlocks
- Learn to Write Your First C Program – Print Hello Computer
- Understand C Variables with Flowcharts and Examples
- C Datatypes Explained with Flowcharts and Examples
- C Operators Learn the Basics of Programming Step by Step
- C Decision Making: If, If-Else, Switch-Case Statements
- C While and Do-While Loops Explained with Examples
- C For Loop – Learn Its Purpose with Flowchart, and Example
- Word Frequency in a Python String | Multiple Techniques – My programming school
- How C Programming Contributes To Machine Learning and its Algorithms