Question 62Asked in BPSC TRE 1.0 (2023) Computer Science Class 11-12

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; }
  1. AHello
  2. BWorld
  3. CError
  4. DMore than one of the above
  5. ENone of the above
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.

From BPSC TRE 1.0 (2023) Computer Science Class 11-12 — Previous Year Paper

This is question 62 of BPSC TRE 1.0 (2023) Computer Science Class 11-12 — Previous Year Paper. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.