Image a situation where we want to use or print a long long string in C or C++, how to do this?
In C/C++, we can break a string at any point in the middle using two double quotes in the middle. Below is a simple example to demonstrate the same.
#include<stdio.h> int main() { // We can put two double quotes anywhere in a string char *str1 = "geeks""quiz"; // We can put space line break between two double quotes char *str2 = "Qeeks" "Quiz"; char *str3 = "Qeeks" "Quiz"; puts(str1); puts(str2); puts(str3); puts("Geeks" // Breaking string in multiple lines "forGeeks"); return 0; } |
Output:
geeksquiz
QeeksQuiz
QeeksQuiz
GeeksforGeeks
Below are few examples with long long strings broken using two double quotes for better readability.
#include<stdio.h> int main() { char *str = "These are reserved words in C language are int, float, " "if, else, for, while etc. An Identifier is a sequence of" "letters and digits, but must start with a letter. " "Underscore ( _ ) is treated as a letter. Identifiers are " "case sensitive. Identifiers are used to name variables," "functions etc."; puts(str); return 0; } |
Output: These are reserved words in C language are int, float, if, else, for, while etc. An Identifier is a sequence ofletters and digits, but must start with a letter. Underscore ( _ ) is treated as a letter. Identifiers are case sensitive. Identifiers are used to name variables,functions etc.
Similarly, we can write long strings in printf and or cout.
#include<stdio.h> int main() { char *str = "An Identifier is a sequence of" "letters and digits, but must start with a letter. " "Underscore ( _ ) is treated as a letter. Identifiers are " "case sensitive. Identifiers are used to name variables," "functions etc."; printf ("These are reserved words in C language are int, float, " "if, else, for, while etc. %s ", str); return 0; } |
Output: These are reserved words in C language are int, float, if, else, for, while etc. An Identifier is a sequence ofletters and digits, but must start with a letter. Underscore ( _ ) is treated as a letter. Identifiers are case sensitive. Identifiers are used to name variables,functions etc.
This article is contributed by Ayush Jain. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Write your own strlen() for a long string padded with '\0's
- Print a long int in C using putchar() only
- Is there any need of "long" data type in C and C++?
- Working of Keyword long in C programming
- Number of common base strings for two strings
- Search strings with the help of given pattern in an Array of strings
- Write a C program to print "Geeks for Geeks" without using a semicolon
- Write a one line C function to round floating point numbers
- Write a C macro PRINT(x) which prints x
- Write one line functions for strcat() and strcmp()
- When should we write our own copy constructor?
- Does C++ compiler create default constructor when we write our own?
- When should we write our own assignment operator in C++?
- Write a C program that does not terminate when Ctrl+C is pressed
- fopen() for an existing file in write mode
- Write a C program that won't compile in C++
- Write a program that produces different results in C and C++
- How to write a running C code without main()?
- Write your own memcpy() and memmove()
- Write a URL in a C++ program

