Difficulty: Medium
Correct Answer: Error
Explanation:
Introduction / Context:This question checks your understanding of C string storage, mutability of string literals, and the behavior of strcat when given an invalid destination. We are asked about the observable outcome under a classic Turbo C (16-bit DOS) environment, which stores string literals in read-only segments or otherwise non-writable memory.
Given Data / Assumptions:
Concept / Approach:strcat requires dest to point to a writable array with enough free space to hold the concatenation. Here, dest is str1, which points to a literal. Writing into a literal violates the C standard’s constraint and results in undefined behavior. Historically, on Turbo C and similar compilers, this typically causes an error or crash rather than clean output.
Step-by-Step Solution:
Identify dest: dest == str1 → points to a literal → not writable.strcat will try to find '\0' at the end of 'India' and copy bytes from 'CURIOUSTAB' into the memory where 'India' resides.This write into read-only storage triggers undefined behavior → practically an error/crash.Verification / Alternative check:Replace str1 with a char array of sufficient size (e.g., char str1[32] = 'India';). Then strcat succeeds and prints 'IndiaCURIOUSTAB IndiaCURIOUSTAB'. The failure only occurs when dest is a literal.
Why Other Options Are Wrong:
CuriousTab India / CuriousTab CuriousTab / India India / India CURIOUSTAB: All assume a successful, defined concatenation. That would require a writable array as destination, which we do not have here.Common Pitfalls:Treating 'char *p = 'text';' as if it were a writable array; forgetting that strcat needs adequate writable space in the destination.
Final Answer:Error.
Discussion & Comments