Back to questions
JuniorTheoryCommon
What does the program print?
let a = 2
let b = 3
print("\(a) + \(b) = \(a + b)")2 + 3 = 5
- Expecting
2 + 3 = 23: thinking+inside a string glues text. Inside\( )the values areInt, so Swift adds them. - Expecting the program not to compile: a blank can hold a whole expression, which Swift works out before filling it in.
- What does
print("\(a)\(b)")print with the sameaandb? - How would you build the same line with
+instead of\( )?