What will be the output of the following C++ code?
Other/Unspecified technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#define MKSTR( x ) #x
int main()
{
cout << MKSTR(HELLO C++) << endl;
return 0;
}
Show answer & explanation
Answer: A. HELLO C++
The preprocessor stringizing operator # converts macro parameter tokens into a string literal, resulting in "HELLO C++" being printed.
Step-by-step Derivation:
Step 1: The preprocessor directive #x replaces parameter x with its stringified literal: #HELLO C++ becomes "HELLO C++".
Step 2: cout << "HELLO C++" prints HELLO C++ to standard output.