Practice mode C Language

Given the macro #define STR(x) #x, what does printf(“%s”, STR(a + b)); print in C?

Correct answer B. a + b

Explanation

The # operator in a function-like macro turns the macro argument into a string literal, so STR(a + b) becomes "a + b". The variables a and b do not even need to exist, because no evaluation happens. This stringising operator is used in assert-style macros to print the text of a failed expression.

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.