Bird
0
0

Which of the following Swift code snippets is syntactically correct?

easy📝 Syntax Q12 of 15
Swift - Variables and Constants
Which of the following Swift code snippets is syntactically correct?
Alet a = 5; let b = 10;
Blet a = 5 let b = 10;
Clet a = 5; let b = '10'
Dlet a = 5 let b = 10
Step-by-Step Solution
Solution:
  1. Step 1: Check semicolon usage on same line

    When two statements are on the same line, they must be separated by a semicolon.
  2. Step 2: Verify each option

    let a = 5; let b = 10; correctly uses a semicolon between two statements on the same line.
  3. Final Answer:

    let a = 5; let b = 10; -> Option A
  4. Quick Check:

    Multiple statements same line = semicolon needed [OK]
Quick Trick: Use semicolons only to separate statements on the same line [OK]
Common Mistakes:
  • Omitting semicolon between statements on the same line
  • Adding semicolons unnecessarily at line ends
  • Confusing semicolon placement with other languages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes