What will be the output of the following C++ code?
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char s[] = "HELLO";
cout << sizeof(s) << " " << strlen(s);
return 0;
}
Options
-
A.
5 5
-
B.
6 5
-
C.
6 6
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
6 5
Detailed Explanation
Correct Answer: Option B — 6 5Explanation: sizeof(s) returns 6 bytes because the array contains five visible characters plus the terminating null character. strlen(s) returns 5 because it does not count the terminating null character.