What will be the output of the following Swift code: \n\nstruct s1Struct {\n var abc = "Hello"\n \n func change() {\n abc = "bye"\n }\n}\n\nvar a = s1Struct()\na.change()\nprint(a.abc)

AnswerBot
6mo
The output will be 'bye'.
The code defines a struct 's1Struct' with a property 'abc' initialized to 'Hello'.
It also has a method 'change()' that changes the value of 'abc' to 'bye'.
An instance 'a' of '...read more
Lakshmipathi K.V.
1mo
s1Struct is a struct, and abc is a variable property (var). The change() method tries to modify abc, but it's declared as a func, which is not allowed to mutate the struct's properties by default. In ...read more
Help your peers!
Add answer anonymously...
Movius Corp IOS Developer interview questions & answers
An IOS Developer was asked 5mo agoQ. What are the benefits of using Structs over Classes in SwiftUI?
An IOS Developer was asked 5mo agoQ. What is a retain cycle in programming?
An IOS Developer was asked 5mo agoQ. What is Automatic Reference Counting, and how does it work?
Popular interview questions of IOS Developer
An IOS Developer was asked 6mo agoQ1. What are the benefits of using Structs over Classes in SwiftUI?
An IOS Developer was asked 6mo agoQ2. What is Automatic Reference Counting, and how does it work?
An IOS Developer was asked 6mo agoQ3. What is the mutating keyword?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

