Saturday, October 1, 2022
HomeC ProgrammingHow you can write multiline macro in C language?

How you can write multiline macro in C language?


How you can write multiline macro in C programming language. We usually outline macros that spans over single line. Nevertheless there exists conditions while you wish to outline a macro that spans over a number of line.

On this put up I’ll clarify methods to write a multiline macro in C language. So allow us to get began.

Required data

Fundamental C programming, Preprocessor directives, Macros

In the course of the course of macros programming workout routines, we learnt fundamentals of macros. How you can outline and undefine a macro. On this put up we are going to proceed forward with macro and can study to outline multiline macro.

For many of the instances macros are candy and quick, prolonged upto single line. Nevertheless, generally we outline difficult macros that spans over a number of strains. Defining these macros in single line will lose code readability, therefore we outline multiline macro .

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 test and print even odd quantity
#outline EVEN_ODD(num)               
    if (num & 1)                    
        printf("%d is oddn", num); 
    else                            
        printf("%d is evenn", num);

int foremost()
{
    int num;

    // Enter quantity from person
    printf("Enter any quantity: ");
    scanf("%d", &num);

    EVEN_ODD(num);

    return 0;
}

Notice: Final line of macro should not include image.

Enter any quantity: 11
11 is odd

Pleased coding 😉

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He likes to study new techs and write programming articles particularly for newbies. He works at Vasudhaika Software program Sols. as a Software program Design Engineer and manages Codeforwin. In brief Pankaj is Internet developer, Blogger, Learner, Tech and Music lover.

Observe on: Twitter | Google | Web site or



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments