How to write multiline macro in C programming language. We typically outline macros that spans over single line. However there exists conditions whenever you need to outline a macro that spans over a number of line.
In this put up I’ll clarify how to write a multiline macro in C language. So allow us to get began.
Table of Contents
Basic C programming, Preprocessor directives, Macros
During the course of macros programming workout routines, we learnt 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 outline multiline macro.
For a lot of the instances macros are candy and short, prolonged upto single line. However, typically we outline difficult macros that spans over a number of traces. Defining these macros in single line will lose code readability, therefore we outline multiline macro .
Read extra How to print supply code of a program?
To outline a multiline macro append
slash on the finish of every line of a macro.
Program to outline multiline macro
/** * C program to create multiline macro */ #embrace <stdio.h> // Macro to examine and print even odd quantity #outline EVEN_ODD(num) if (num & 1) printf("%d is oddn", num); else printf("%d is evenn", num); int most important() int num; // Input quantity from consumer printf("Enter any number: "); scanf("%d", &num); EVEN_ODD(num); return 0;
Note: Last line of macro should not comprise
Enter any quantity: 11 11 is odd
Happy coding 😉