Home > Backend Development > C++ > Multi-line macro in C language

Multi-line macro in C language

PHPz
Release: 2023-08-31 18:21:05
forward
1129 people have browsed it

Multi-line macro in C language

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("</p><p>");\
})
int main() {
   int x = 10;
   if(x % 2 == 0){
      PRINT(x, EVEN);
   }
}
Copy after login

输出

The number 10 is EVEN
Copy after login

The above is the detailed content of Multi-line macro in C language. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template