Bird
0
0

In Swift, if you create a new String by assigning an existing string variable and then change the new string, what will be the value of the original string?

easy📝 Conceptual Q2 of 15
Swift - Data Types
In Swift, if you create a new String by assigning an existing string variable and then change the new string, what will be the value of the original string?
AThe program throws a runtime error
BThe original string changes to match the new string
CBoth strings become empty
DThe original string remains unchanged
Step-by-Step Solution
Solution:
  1. Step 1: Understand value type behavior

    Strings in Swift are value types, so assigning one string to another copies the value.
  2. Step 2: Modify the new string

    Changing the new string does not affect the original because they are independent copies.
  3. Final Answer:

    The original string remains unchanged -> Option D
  4. Quick Check:

    Original string unchanged after modifying copy [OK]
Quick Trick: Strings are copied, original stays intact [OK]
Common Mistakes:
  • Assuming strings are reference types and both change
  • Believing modifying one string affects the other

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes