Bird
0
0

Find the error in this Swift code snippet:

medium📝 Debug Q14 of 15
Swift - Basics and Runtime

Find the error in this Swift code snippet:

let age = 25
print("Age is: " + age)
AMissing parentheses in print.
BCannot add String and Int directly.
CVariable age is not declared.
Dprint function is misspelled.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the print statement

    The code tries to add a String and an Int using +, which is not allowed in Swift.
  2. Step 2: Identify correct way to combine String and Int

    Use string interpolation like "Age is: \(age)" instead of + operator.
  3. Final Answer:

    Cannot add String and Int directly. -> Option B
  4. Quick Check:

    String + Int needs interpolation [OK]
Quick Trick: Use \(variable) to combine text and numbers [OK]
Common Mistakes:
  • Trying to add String and Int
  • Missing string interpolation
  • Assuming + works for different types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes