The following 2 symbols: =
and /=
are assignment operators. They are used to set the variable on the right to the value or variable on the right. The =
operator is simple; it does no operation on the value on the left. So, if we have a statement like:
int x = 5;
The equality assignment operator here simply sets x to 5.
The second operator in the line of code you are confused about is a part of the compound assignment operator group. This operator does 2 operations: it first takes the value stored in the variable on the left side of the operator, divides it by the value on the right side of the operator, and stores it again in the variable on the left side of the operator. Therefore, if we take this simple piece of code:
int y = 25;
y /= 5;
This piece of code declares a variable of type int, initialized to 25. The second line divides the value of y
by 5, ad updates the variable y with the resulting value of the mathematical operation.
Now, we are not restricted to having a fixed value, a variable, or a function's return value as a statement on the right side of the assignment operator. We can very well evaluate an expression (like here we do y[i] /= ((double)/n)
, and then assign the updated value of y[i]
to x[i]
. The compiler merely evaluates the expression on the right first, and then moves on to assign it to the left-hand variable.
Now, having this explaination, we can summarize this line very easily:
x[i] = y[i]/=((double)n);
The compiler divides the value of y[i]
by the value n, casted as a double (unrequired here as y
itself is of type double), assigns the new value to y[i]
, and then assigns x[i]
the updated value of y[i]
.