Difficulty: Easy
Correct Answer: Error
Explanation:
Introduction / Context:This problem highlights type correctness in C: a string literal represents an array of characters, while a single char variable stores only one character. It also checks awareness that %s expects a char* (pointer to char), not a char value.
Given Data / Assumptions:
Concept / Approach:char str = 'CuriousTab' is ill-formed; in standard C, multi-character constants like 'AB' are integer constants, but string literals use double quotes. Here double quotes are used, so assigning a string literal to char is a compilation error. Even if it compiled erroneously, printf('%s', str) would require a pointer, not a char, causing undefined behavior. Proper code would be either char str[] = 'CuriousTab'; or char str = 'CuriousTab';
Step-by-Step Solution:
Compilation stage: detect type mismatch (char vs. char[...]).printf usage: %s needs char, not char.Therefore the code fails to compile correctly; treat as an error.Verification / Alternative check:Change declaration to char str[] = 'CuriousTab'; and the program will print the word as expected.
Why Other Options Are Wrong:
Printing 'CuriousTab' or base address presumes a valid pointer and a correct format specifier, which we do not have.'No output': compilation fails before runtime.'Program prints a single C': not applicable to this code as written.Common Pitfalls:Confusing single characters (char) with strings (arrays/pointers to char) and mismatching printf format specifiers.
Final Answer:Error.
Discussion & Comments