What is the output of the following snippet? #include <iostream> #include <string> using namespace std; int main() { int i = 2; string s = "2"; cout << s + i; } 2 4 Compilation fails 2
Question
What is the output of the following snippet?
#include <iostream> #include <string>
using namespace std;
int main() { int i = 2; string s = "2";
cout << s + i;
}
2
4
Compilation fails
2
🧐 Not the exact question you are looking for?Go ask a question
Solution
The compilation fails. In C++, you cannot directly add an integer to a string using the '+' operator.
Similar Questions
What is the output for the following code?
What does the following code snippet do?
What is the output of the following code in Python?
What is the output for the following code?Note: This question helps in clearing conceptual technical interviews for service-based companies.
What will be the output of the following PHP code?
1/4
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.