Bird
0
0

Which of the following is the correct way to declare a constant in Swift?

easy📝 Syntax Q12 of 15
iOS Swift - Swift Language Essentials
Which of the following is the correct way to declare a constant in Swift?
Avar pi = 3.14
Bconstant pi = 3.14
Cconst pi = 3.14
Dlet pi = 3.14
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift syntax for constants

    Swift uses let to declare constants that cannot change.
  2. Step 2: Identify the correct syntax

    var declares variables, const and constant are not Swift keywords.
  3. Final Answer:

    let pi = 3.14 -> Option D
  4. Quick Check:

    Constants use let keyword [OK]
Quick Trick: Use let for constants, var for variables [OK]
Common Mistakes:
  • Using var instead of let for constants
  • Using const or constant which are not Swift keywords
  • Confusing variable and constant declarations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes