+ 3
I don't understand this! Please help
var a = 3 let b = a++ let c = -b How come the value of 'c' was -3?
5 odpowiedzi
+ 4
var a = 3 //initially
let b = a++ //post increment b become 3
let c = -b //now c=-b=-3 because value of b is -3 which assign to c
so the output is -3
+ 3
a++
a--
this ++ or -- called increments and decrement operator..
it increased by 1 or decreased by 1 the value of variables..
there are two types.
post increments and decrement operator
and
pre increments and decrement operator..
a++ is post increments.
++a is pre increments.
post increments operator has the
priority has less then equal to..(=)operator
and
pre increments operator has the priority great than equal to operator..
now back to your question..
a=3;
b=a++
as you see a++ post increments operator it mean it assigned value firsr then increased by one..
so
b=3. and a become 4
third statement is
c=-b
as you know now b has the value is 3..
and you assigned b value with the sign- to c..
i.e c is -3
you must read this for better understand
https://www.sololearn.com/learn/2283/?ref=app
+ 2
When you do “let b = a++”, b is set to a, THEN a goes up. So, after “let b = a++”, a = 4, and b is still 3. At “let c = -b”, b = 3, so you’re saying to the compiler “let c = -3”. If you put “let b = ++a”, then b AND a would equal 4.
0
Hi
0
Telegram @L_Vuitton