
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Multiline macros in 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("
");\ }) int main() { int x = 10; if(x % 2 == 0){ PRINT(x, EVEN); } }
Output
The number 10 is EVEN
- Related Articles
- Hygienic Macros in C
- Macros and Preprocessors in C
- Macros vs Functions in C
- Variable length arguments for Macros in C
- What are macros in C programming language?
- Data Type Ranges and their macros in C++
- Data types ranges and their macros in C++
- C++ program to demonstrate function of macros
- How to define multiline String Literal in C#?
- Multiline Strings in Perl
- JavaScript multiline Property
- Using BU, ZK code in SAP Macros
- Pattern MULTILINE field in Java with examples
- How do we create multiline comments in Python?
- How to grep multiline search patterns in Linux?

Advertisements