Bird
0
0

What will be printed by this Swift code?

medium📝 Predict Output Q5 of 15
Swift - Data Types
What will be printed by this Swift code?
let value = 0xFF + 0o10
print(value)
AError: Cannot add different literal types
B265
C0xFF10
D263
Step-by-Step Solution
Solution:
  1. Step 1: Convert hexadecimal and octal literals to decimal

    0xFF is 255 decimal. 0o10 is 8 decimal.
  2. Step 2: Add the decimal values

    255 + 8 = 263.
  3. Final Answer:

    263 -> Option D
  4. Quick Check:

    Hex + Octal addition = 263 [OK]
Quick Trick: Swift converts literals to decimal before operations [OK]
Common Mistakes:
  • Adding literals as strings instead of numbers
  • Confusing octal 10 as decimal 10
  • Expecting output in hex or octal format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes