Wednesday, April 24, 2024
HomeC ProgrammingMethods to write multiline macro in C language?

Methods to write multiline macro in C language?


Methods to write multiline macro in C programming language. We typically outline macros that spans over single line. Nonetheless there exists conditions whenever 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 information

Primary C programming, Preprocessor directives, Macros

Throughout the course of macros programming workouts, we learnt fundamentals of macros. Methods to outline and undefine a macro. On this put up we are going to proceed forward with macro and can be taught to outline multiline macro.

For a lot of the occasions macros are candy and quick, prolonged upto single line. Nonetheless, typically we outline sophisticated macros that spans over a number of traces. 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 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 predominant()
{
    int num;

    // Enter quantity from consumer
    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

Comfortable coding ?‍?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments