In C formatting, what is the exact output produced by adjacent string literal concatenation and a ternary expression? #include <stdio.h> int main() { int k = 1; printf("%d == 1 is" "%s ", k, k == 1 ? "TRUE" : "FALSE"); return 0; }

Difficulty: Easy

Correct Answer: 1 == 1 isTRUE

Explanation:


Introduction / Context:
The problem demonstrates two C features: (1) adjacent string literals are concatenated at compile time, and (2) the ternary operator chooses the appropriate string to print. It asks for the exact text produced, including spacing.


Given Data / Assumptions:

  • k is 1.
  • The format string is written as two adjacent literals: "%d == 1 is" and "%s\n".
  • Concatenation creates the single format string "%d == 1 is%s\n" (note the absence of a space before %s).


Concept / Approach:
Because k equals 1, the conditional expression selects "TRUE". The printf therefore substitutes k for %d and "TRUE" for %s. There is no extra space inserted between "is" and the %s field—so the output joins them directly.


Step-by-Step Solution:
Concatenated format → "%d == 1 is%s\n".Substitute k = 1 and string "TRUE".Printed line → "1 == 1 isTRUE" followed by a newline.


Verification / Alternative check:
Adding a space inside the first literal (e.g., "is ") would yield "1 == 1 is TRUE"; however, the given code has no space.


Why Other Options Are Wrong:
Options with a space do not match the exact format. The false option contradicts k == 1. The one using a lowercase k misprints the literal text.


Common Pitfalls:
Assuming printf inserts a space automatically; it does not. Spacing must be explicit in the format string.


Final Answer:
1 == 1 isTRUE

More Questions from Input / Output

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion