0

Why is the output same whether i write i++ or ++i

Istarric right angle triangle https://code.sololearn.com/cvWzsPxNRAQ1/?ref=app

16th Nov 2020, 3:55 PM
Anas kayani
Anas kayani - avatar
4 Respuestas
+ 4
BeegCat I was informed that it matters insignificantly when it comes to built-in types (here loop counter type - `int`). When working with objects, where the class implements overload for increment operator (post and/or pre), then it needs to be considered. Because it helps reduce possibility of creating a copy of the object to return by the overload 👍
16th Nov 2020, 4:28 PM
Ipang
+ 1
y = ++x : x = x + 1 y = x y = x++ : y = x x = x + 1 When only used to increment x. x++ is used most of the time.
17th Nov 2020, 8:42 AM
R3dSt0ne
R3dSt0ne - avatar
0
Inside for...loop definition they behave the same, no difference at all ...
16th Nov 2020, 3:58 PM
Ipang
0
Ok thanks 😌
16th Nov 2020, 3:59 PM
Anas kayani
Anas kayani - avatar