What will be the output of the following C++ code? int main(int argc, char const *argv[ ])
What will be the output of the following C++ code?
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char const *argv[ ])
{
char s1[6]="Hello";
char s2[6]="World";
char s3[12]=s1+" "+s2;
cout<<s3;
return 0;
}
Show answerHide answer
Correct answer: (C) Error
Explanation
Char arrays cannot be joined with +. s1 + " " tries to add two pointers, which is invalid, and an array cannot be initialised from such an expression, so the code gives a compile error.