Bird
0
0

Why does Swift require parentheses around expressions inside string interpolation?

hard📝 Conceptual Q10 of 15
Swift - Variables and Constants
Why does Swift require parentheses around expressions inside string interpolation?
ATo make the code run faster
BTo prevent the string from being printed
CTo allow interpolation only of variables, not expressions
DTo clearly separate the expression from surrounding text
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of parentheses in interpolation

    Parentheses group the expression so Swift knows what to evaluate.
  2. Step 2: Identify why parentheses are needed

    They separate the expression from the rest of the string clearly.
  3. Final Answer:

    To clearly separate the expression from surrounding text -> Option D
  4. Quick Check:

    Parentheses clarify expression boundaries in interpolation [OK]
Quick Trick: Parentheses group expressions inside \( ) for clarity [OK]
Common Mistakes:
  • Thinking parentheses speed up code
  • Believing only variables can be interpolated
  • Assuming parentheses prevent printing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes