What will be the output of the following C++ code?

#include <iostream>
using namespace std;
int main() {
    char s[] = "Hello";
    cout << s;
    return 0;
}
                        

Options

  • A. Hello
  • B. H
  • C. Error
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. Hello

Detailed Explanation

Correct Answer: Option A — Hello

Explanation: The character array is initialized with the characters H, e, l, l, o and a terminating null character. When passed to cout, it is printed as a C-style string.