Bird
0
0

You have a constant declared as let base = 10. You want to calculate the area of a square with this base. Which Swift code correctly uses the constant in the calculation?

hard📝 Application Q9 of 15
Swift - Variables and Constants
You have a constant declared as let base = 10. You want to calculate the area of a square with this base. Which Swift code correctly uses the constant in the calculation?
Alet area = base * base
Bvar area = base + base
Clet area = base / 2
Dlet area = base - base
Step-by-Step Solution
Solution:
  1. Step 1: Understand the formula for square area

    The area of a square is side length multiplied by itself.
  2. Step 2: Use the constant in the calculation

    let area = base * base correctly calculates the area using the constant base.
  3. Final Answer:

    let area = base * base -> Option A
  4. Quick Check:

    Use constants in expressions without reassignment [OK]
Quick Trick: Use let constants directly in calculations [OK]
Common Mistakes:
  • Using addition or subtraction instead of multiplication
  • Declaring area as var unnecessarily
  • Dividing base instead of multiplying

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes