0

Need help with c++

Can someone pleeeasee help...I don't really understad what for example "x+=5" means :(

14th Apr 2017, 6:59 PM
kawan azizi
kawan azizi - avatar
3 Answers
+ 3
x += 5: You are adding 5 to the current value of x. x -= 5: You are subtracting 5 to the current value of x. x *= 5: You are multiplying the current value of x by 5. x /= 5: You are dividing the current value of x by 5.
14th Apr 2017, 7:55 PM
Denis Felipe
Denis Felipe - avatar
+ 2
it means x = x +5; for example you have a cycle: int x=0; for(int i=0;i<10;i++){ x+=5; } /// when i=0; x=x+5;-->x=0+5; when i=1; x=x+5;--->x=5+5; when i=2; x=x+5 or x+=5;--> x=10+5; and ... it's shortcut way to write for all programmers(because programmers are lazy to write long constructions ) :)
14th Apr 2017, 7:03 PM
Nikita Galchenko
Nikita Galchenko - avatar
+ 1
in general it's a short hand for x = x + 5, especially if x is of some numeric type like int But: in C++ (and several other languages) it is possible to overload operators. then it depends on the implementation of the operator and that can be condusing. Please DON'T abuse this posibility, the example below you should NOT use: https://code.sololearn.com/cUzfWi5651iM/?ref=app
15th Apr 2017, 12:35 AM
Volker Milbrandt
Volker Milbrandt - avatar