How to write long strings in Multi-lines C/C++?


Long strings can be written in multiple lines by using two double quotes ( “ “ ) to break the string at any point in the middle.

A program that demonstrates this in C is given as follows.

Example

 Live Demo

#include <stdio.h>
int main() {
   char *str = "This is the method "
               "to write long strings "
               "in multiple lines in C";
   puts(str);
   return 0;
}

Output

The output of the above program is as follows.

This is the method to write long strings in multiple lines in C

Now let us understand the above program.

The string str can be written in multiple lines by using two double quotes ( “ “ ) to break the string at any point in the middle. Then the string is displayed using puts. The code snippet that shows this is as follows.

char *str = "This is the method "
"to write long strings "
"in multiple lines in C";
puts(str);

Updated on: 26-Jun-2020

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements