Difficulty: Medium
Correct Answer: 1022 Hello2
Explanation:
Introduction / Context:This question examines pointer types with string literals, how the unary & operator changes the type, and how printf interprets arguments for %u and %s. It also assumes a specific address (1022) for the literal 'Hello1' to make the numeric output deterministic.
Given Data / Assumptions:
Concept / Approach:Although the pointer types are not char*, the numeric value of &'Hello1' prints as the base address. For %s, &'Hello2' is treated as the base address of the literal string. On many older compilers, this prints correctly despite the subtle type mismatch (on modern compilers, you would cast explicitly).
Step-by-Step Solution:
%u with &'Hello1' → prints its address → 1022 (as given).%s with &'Hello2' → prints the characters from that base address → 'Hello2'.Verification / Alternative check:Replacing &'Hello2' with 'Hello2' (which decays to char*) still prints 'Hello2'. Both point to the same base address.
Why Other Options Are Wrong:
'Hello1 1022' or 'Hello1 Hello2': would require using %s with 'Hello1' and not printing the numeric address.'1022 1022': incorrectly assumes both conversions produce numeric printing.'Error': legacy compilers typically accept this; behavior shown is the intended trick.Common Pitfalls:Confusing &'literal' with the decayed char* of a literal; assuming %s requires exactly char* and not recognizing platform permissiveness in old toolchains.
Final Answer:1022 Hello2.
Discussion & Comments