I was checking some code online when i found the following statement
number /= 10;
I know that /
mean divison and =
is the assignment operator but i don't understand what it does in this case.
It means that whatever the value number contains will be divided by 10 and the result will be stored back into number.
It is exactly equivalent to
number = number / 10
Most of the major operators have it:
number *= 10
number += 10
number -= 10
number %= 10
number >>= 10
number <<= 10
It means
number =number/10;
Number divided by 10
you can also do
number operator=number
where operator can be +
, /
, *
This is the shorter notation for number = number / 10;
The same exists for the other operators as well:
x += y;
=> x = x + y;
x -= y;
=> x = x - y;
x *= y;
=> x = x * y;
x %= y;
=> x = x % y;
It is equivalent of -
number = number / 10;
It is a composite operator - consist of division and assignment. You may found something like this -
+=
-=
%= etc.
All of these above works similarly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.