Bird
0
0

Which of the following is a correct way to declare a constant string named greeting with the value "Hello" in Swift?

easy📝 Conceptual Q2 of 15
Swift - Variables and Constants
Which of the following is a correct way to declare a constant string named greeting with the value "Hello" in Swift?
Aconst greeting = "Hello"
Bvar greeting = "Hello"
Clet greeting = "Hello"
Dconstant greeting = "Hello"
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct Swift syntax for constants

    Swift uses let to declare constants, not const or constant.
  2. Step 2: Check the assignment

    The syntax let greeting = "Hello" correctly declares a constant string with the value "Hello".
  3. Final Answer:

    let greeting = "Hello" -> Option C
  4. Quick Check:

    Constant declaration = let [OK]
Quick Trick: Use let for constants, var for variables [OK]
Common Mistakes:
  • Using var instead of let for constants
  • Using const or constant keywords (not Swift)
  • Missing quotes around string values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes