Difficulty: Easy
Correct Answer: Learn Java Programming!
Explanation:
Introduction / Context:
This item checks understanding of C-style string operations (strcpy, strcat) and how default parameters work when some but not all constructor arguments are provided. The Display() method prints the buffer z built by the three-argument constructor.
Given Data / Assumptions:
(char* xx, char* yy = " C++", char* zz = " Programming!")
.CuriousTabString objStr("Learn", " Java");
so xx = "Learn"
, yy = " Java"
, zz
takes the default " Programming!"
.
Concept / Approach:
The constructor copies xx
into z
, then concatenates yy
, then concatenates zz
. Because yy
and zz
include leading spaces, they create word spacing naturally in the result.
Step-by-Step Solution:
z = "Learn"
.Concatenate yy
: z = "Learn Java"
.Concatenate default zz
: z = "Learn Java Programming!"
.Display() prints the final string.
Verification / Alternative check:
Changing the call to ("Learn")
would use the one-parameter constructor and not initialize z
; Display() would then print an uninitialized buffer (undefined). The two-parameter constructor is the correct usage here.
Why Other Options Are Wrong:
Learn
prefix or use the wrong defaults ordering.
Common Pitfalls:
Forgetting that default arguments keep their specified leading spaces; omitting them causes words to touch.
Final Answer:
Learn Java Programming!
Discussion & Comments