- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What happen if we concatenate two string literals in C++?
In this section we will see another property of string and string literals. If we want to concatenate two strings in C++, we have to remember some of things.
If x + y is the expression of string concatenation, where x and y both are string. Then the result of this expression will be a copy of the character of string x followed by the characters of string y.
Either x or y can be a string literal or character, but not both. If both are string literal, they will not be concatenated.
Example Code
#include<iostream> using namespace std; main(){ cout << "Hello " + "World"; }
Output
The above code will not be compiled because both of the operands are literals.
Here the left associativity of the operator ‘+’ is returning the error. If one of them is string, then it will work properly.
Example Code
#include<iostream> using namespace std; main(){ string my_str = "Hello "; cout << my_str + "World"; }
Output
Hello World
- Related Articles
- What are string literals in C#?
- What are string literals in C language?
- Formatted string literals in C#
- What will happen if we don't have platelets?
- What is the type of string literals in C/ C++?
- What is the type of string literals in C and C++?
- What are Perl String Literals?
- What does the @ prefix do on string literals in C#?
- What is the difference between character literals and string literals in Java?
- Character constants vs String literals in C#
- What will happen if we directly call the run() method in Java?
- What would happen if we run SELECT WHERE columnName = zero in MySQL?
- What will happen, if we did not have cartilage in our body?
- What are literals in C++?
- How can we concatenate two strings using jQuery?

Advertisements