*= Operator

This might be a stupid question, but what does *= operator do?

I have these two statements in the code:

1
2
double NoverL = N/L;
NoverL *= 1.0-Mratio(2)-Mratio(3);
It's just multiplication in this case. The same as writing:

NoverL = NoverL * (1.0-Mratio(2)-Mratio(3));
Off course..Thanks.
It's a compact way of modifying the variable on the left of the operator, then assigning the result to it. These examples all do the same thing:
1
2
a = a * b;
a *= b;


With long variable names it's useful:
1
2
longVariableNameHere = longVariableNameHere  * b;
longVariableNameHere  *= b;


The resulting code might be more efficient too, though modern compilers should optimise the code so it makes little or no difference.

The same style applies to other operations combined with = too.
http://www.cplusplus.com/doc/tutorial/operators/
Topic archived. No new replies allowed.