Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

What does x *= x mean?

+7 votes
asked Oct 6, 2016 in CSC 211 (F16) by Alyssa Nestor (100 points)

2 Answers

+7 votes
It's basically "x = x * x;"

Just remember that the *= expression is to multiply the number on the left with the number on the right. The same goes with /= += -=.
answered Oct 6, 2016 by Minh Ta (1,045 points)
+3 votes
When you have that format: <variable><operation><equals><value>, you perform the operation applied to the two sides and store that value in the left hand side. In other words, x *= x is equivalent to x = x * x. You can also do this with +=, -=, *=, /=, and %= (and others). These are called compound assignment operators.

http://java.about.com/od/c/g/compoundassgnment.htm has some more information.
answered Oct 6, 2016 by Vecna (1,043 points)