0

Different incremental variable.

Please I'm kinda confused with these incremental variables: x++, ++x, x+=1. Do theyean the same thing, how do they differ if they do?

28th Feb 2020, 5:38 PM
Marvellous Abia
Marvellous Abia - avatar
6 ответов
+ 3
All three produesd same answer
28th Feb 2020, 6:01 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
28th Feb 2020, 5:45 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
They all just add by one. The only difference is that x++ and ++x have different precedence. +=some number identifies what to increment by. Because this case it's one it is equivalent to x++ In conclusion, x is added by one on all three cases making the answer of three on all of them Marvellous Abia
28th Feb 2020, 6:05 PM
Minerals2016
Minerals2016 - avatar
0
x++ takes the variable x first and then increments it by 1 ++X increments by 1 first and then checks x x+=1 basically means x=x+1. That states that the variable will be incremented by itself by 1 (in this case it's equivalent to x++). The 1 can be changed here to increment by different amounts Hope this helps :)
28th Feb 2020, 5:54 PM
Minerals2016
Minerals2016 - avatar
0
Sumit Programmer😎😎, Minerals2016 . Please what will the following evaluate to: x=2 x++ print x x = 2 ++x print x x=2 x+=1 print x
28th Feb 2020, 6:00 PM
Marvellous Abia
Marvellous Abia - avatar