Difficulty: Medium
Correct Answer: CURIOUSTAB
Explanation:
Introduction / Context:
This classic pointer-copy loop uses the assignment expression inside the while condition to copy bytes from a source string to a destination and stops when the terminating null is copied. The example also prints the destination after each successful character copy. To avoid undefined behavior, we explicitly assume str1 has enough storage for the entire copy (for example, char str1[20] = "India").
Given Data / Assumptions:
Concept / Approach:
At each iteration, one character from str2 overwrites the next position in str1. Initially str1 contains "India"; after 10 character copies and the final null byte, str1 holds an exact copy of str2. The prints inside the loop show intermediate states, but the question asks for the final content of str1, which equals the source string.
Step-by-Step Solution:
Verification / Alternative check:
Print str1 after the loop (outside the while). It shows “CURIOUSTAB”. The in-loop prints show transitional states but do not alter the final result.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting to size the destination buffer to avoid overflow; misreading the assignment-in-condition idiom; confusing “console output during the loop” with the final string state in memory.
Final Answer:
CURIOUSTAB.
Discussion & Comments