0

# Need help with c++

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

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.

+ 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 ) :)

+ 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