Difficulty: Easy
Correct Answer: printf("\n");
Explanation:
Introduction / Context:
Escape sequences in C string literals can be confusing. The backslash introduces special sequences like \n (newline). To print a backslash character itself, you must escape it as \\ in the source to produce a single backslash at runtime. This question asks for the exact printf form to display the text \n literally, not to create a newline.
Given Data / Assumptions:
Concept / Approach:
In C string literals, "\" represents a single backslash character. Therefore, "\n" in a literal results in two output characters: backslash and n. Passing that literal to printf prints \n exactly as text. Using '\n' (single quotes) forms a character literal representing newline, not the two-character sequence.
Step-by-Step Solution:
Write a string literal that encodes backslash: "\".Append the character n to form "\n".Call printf("\n"); to print those two characters.Do not use character literals or unescaped backslashes.
Verification / Alternative check:
Running printf("\n"); produces backslash-n on the console. Running printf("\\n"); would print two backslashes followed by n (i.e., \\n).
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that backslash must be escaped in string literals. Confusing character and string literals leads to different behavior.
Final Answer:
printf("\n");.
Discussion & Comments