What will be the output of the following C++ code using strcat()?
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char s1[10] = "Hi";
char s2[] = "All";
strcat(s1, s2);
cout << s1;
return 0;
}
Options
-
A.
Hi
-
B.
All
-
C.
HiAll
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
C.
HiAll
Detailed Explanation
Correct Answer: Option C — HiAllExplanation: strcat() appends the C-style string s2 to the end of s1, including the characters before its terminating null character. The destination array has enough capacity for HiAll and its terminating null character.