Bird
0
0

What will be the output of this Swift code?

medium📝 Predict Output Q4 of 15
Swift - Variables and Constants
What will be the output of this Swift code?
let temperature = 22
print("It is currently \(temperature)°C outside.")
AIt is currently temperature°C outside.
BIt is currently \(temperature)°C outside.
CIt is currently 22°C outside.
DIt is currently 22 outside.
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation in print

    The \(temperature) inserts the value 22 into the string.
  2. Step 2: Predict the printed string

    The output will show the number 22 followed by °C as part of the string.
  3. Final Answer:

    It is currently 22°C outside. -> Option C
  4. Quick Check:

    Interpolation inserts variable value in string [OK]
Quick Trick: Variables inside \( ) show their values in strings [OK]
Common Mistakes:
  • Printing the literal \(temperature) instead of value
  • Omitting the degree symbol
  • Confusing variable name with its value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes