Bird
0
0

Which of the following is the correct way to declare a constant integer named age with value 30 in Swift?

easy📝 Syntax Q12 of 15
Swift - Variables and Constants
Which of the following is the correct way to declare a constant integer named age with value 30 in Swift?
Alet age = 30
Bvar age = 30
Cconstant age = 30
Dconst age = 30
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct Swift syntax for constants

    In Swift, let is used to declare constants, so let age = 30 is correct.
  2. Step 2: Check other options

    var declares a variable, not a constant. constant and const are not valid Swift keywords.
  3. Final Answer:

    let age = 30 -> Option A
  4. Quick Check:

    Use let for constants = B [OK]
Quick Trick: Use let for constants, var for variables [OK]
Common Mistakes:
  • Using var instead of let for constants
  • Using non-Swift keywords like const
  • Syntax errors with declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes