Difficulty: Medium
Correct Answer: 300
Explanation:
Introduction / Context:
This problem tests understanding of string literals, pointer arithmetic, and how printf uses a format string. The code manipulates a pointer into the literal "%d\n" and then passes an adjusted pointer back to printf.
Given Data / Assumptions:
Concept / Approach:
After two increments, str points at '\n'. Subtracting 2 moves the pointer back to '%'. Therefore, the format string passed to printf is effectively "%d\n". With the integer argument 300 supplied, printf prints the decimal representation followed by a newline.
Step-by-Step Solution:
Verification / Alternative check:
Replace the subtraction with a direct literal in printf and confirm identical output.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting the actual byte layout of the format string and miscounting pointer steps; assuming pointer math corrupts the pointer when it actually returns to a valid position within the same literal.
Final Answer:
300.
Discussion & Comments