Assuming standard headers and using namespace std, what does this C++ code print? char c = ‘A’ + 2; cout << c << ” ” << int(c);
Correct answer A. C 67
Explanation
A char holds a small integer code, and in ASCII 'A' is 65, so 'A' + 2 is 67, which is the code for 'C'. Streaming a char prints it as a character, while int(c) converts it so the numeric code 67 is printed instead. This is why char arithmetic is a common way to step through letters.
Answer checked How we write and check questions
Discussion