Originally posted by Thomas Paul:
You were taught incorrectly. As long as there are no variables on the right hand side there isn't a problem.
Well, in the case that the value to be assigned
fits within the assigned variable, there isn't a problem.
Notice that this works:
while this causes an error:
The reason for this is that the compiler can determine if the value being assigned can fit within the variable that it is being assigned to. This can be done because you're assigning a constant value. If you were to use a variable, the compiler wouldn't know if it fit in a variable or not and, hence, would
always throw an error.
This works:
while this doesn't:
Even though we can see that 3 will be assigned to the char and we know that 3 fits within the range, the compiler isn't sure what the value of i will be when the assignment occurs. Therefore, an error is issued.
I hope that helps,
Corey