Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Line Splicing in C/C++
In C/C++, Line splicing is a small feature that lets you split one long line of code into two lines by using a special symbol that is the backslash (\).
Line splicing is a preprocessor feature, not a function or method. It does not have any parameters. But it simply affects how lines of code are interpreted by the preprocessor before compilation.
How to Use Line Splicing?
If a line of code is too long, and you want to break it into multiple lines to make it easier to read. You can use a backslash at the end of a line to tell the compiler that "This line continues on the next line".
C Example of Line Splicing
This C example prints a long message by splitting it into two lines in the code using line splicing with a backslash (''):
#include<stdio.h>
int main() {
printf("This is a very long message \
that is split into two lines using line splicing.\n");
return 0;
}
Following is the output to the above program:
This is a very long message that is split into two lines using line splicing.
C++ Example of Line Splicing
This program shows how to use line splicing (\) in C++ to split a long string into two lines without breaking the output:
#include<iostream>
using namespace std;
int main() {
cout<<"Line splicing is useful in C++ \
when you want to split long lines of code.";
return 0;
}
Following is the output to the above program:
Line splicing is useful in C++ when you want to split long lines of code.