Hi,
This is one of the advantages of the Compound Assignment Operator +=
When you do any integer arithmetic with byte values, the compiler expects you to put an explicit cast before assigning the result to a byte variable.
For example,
byte a = 3;
a = a + 5; //won't compile,
//needs an explicit cast
a = (byte) a + 5; But when you do the same thing with Compound Assignment operator,We are ensuring the Compiler that the resulting value will definitely fit to a byte variable.
See this,
byte a = 3;
a += 5; //Compiles without any error.
Hope this answers your question.
Thanks,
Sathya.
