AI编程助手
AI免费问答

C语言中的多行宏

PHPz   2023-08-31 18:21   1152浏览 转载

c语言中的多行宏

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

输出

The number 10 is EVEN

13万字C语言保姆级教程(深入):立即学习
在学习笔记中,你将探索c语言的核心概念和高级技巧!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除