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.
#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); } }
The number 10 is EVEN
以上就是C语言中的多行宏的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号