Difference between += and =+

    If you use it a lot, it doesn't mean you really know it. Every technical problem really needs to be deeply cultivated and studied at every point.

    The following is a very simple question, but not everyone can answer it

     What is the difference between i=i+1 and i+= 1?

     I think a lot of people will say that there is no difference except the way of writing, isn't the result the same? If you ask me that, I think you may lack the habit of thinking deeply. What if I change the subject?

    short i=0 

     What is the difference between i=i+1 and i+= 1?

    At this time, your compiler will tell you the answer. The first compiler will report an error, but the second one will not, because += will automatically convert the result to the type on the left side of the symbol, while the first one will not. But i+1 is automatically converted to an integer, and i is of type short, so it will look like this:

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325510330&siteId=291194637