Practice mode C++

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.