Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of this: "double x = x = (a - b) / (c - 1);"

Tags:

c#

I came across this code in which a variable is assigned to itself for no good reason.

double x = x = (a - b) / (c - 1);

It is not making much sense to me. Is there a reason behind this?

like image 758
Saeid Avatar asked Feb 01 '16 13:02

Saeid


1 Answers

When assigning multiple variables at once all the variables will get the value of the right hand operand. Doing this double assignment does not provide any value, it will probably even be optimzed to double x = (a - b) / (c - 1); by the compiler. This is definately a typo.

like image 187
Simon Karlsson Avatar answered Nov 14 '22 23:11

Simon Karlsson