0

Can someone explain in details?

var a = 0 let b = ++a let c = a++ print ("\(a) \(b) \(c)") How come the result was 2 1 1 ?

26th May 2018, 12:30 PM
Ax9
3 Answers
0
var a = 0 let b = ++a let c = a++ print ("\(a) \(b) \(c)") a=0 then first pre increment a become 1 then post increment a become 2 when it is again called after c so value of a=2, b=1 ,c=1 b=++a=1 (here a is 0 then change after increment b=1) c=a++=1(here a is 1 then post increment it remains 1 but when it called in print it becomes 2 so c=1 a=2) print("\(a) \(b) \(c) ") so a=2 b=1 c=1
26th May 2018, 12:37 PM
MsJ
MsJ - avatar
0
why cant u know ode
29th May 2018, 3:19 PM
Shogeyinbo Adenike
0
i am sorry my son did that
29th May 2018, 3:20 PM
Shogeyinbo Adenike