Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Anvi Jain

In this section we will see, how can write multiline macros in C. We can write multiline macros like functions, but for macros, each line must be terminated with backslash ‘\’ character. If we use curly braces ‘{}’ and the macros is ended with ‘}’, then it may generate some error. So we can enclose the entire thing into parenthesis.

Please check the following program to get the idea about multiline macros.

Example

#include<stdio.h>
#define PRINT(x, str) ({\
   printf("The number %d", x);\
   printf(" is ");\
   printf(#str);\
   printf("\n");\
})
int main() {
   int x = 10;
   if(x % 2 == 0){
      PRINT(x, EVEN);
   }
}

Output

The number 10 is EVEN

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.