Hello Mr. Kasak Tahilramani First thing is that the following expression (true) ? b = b + 1 : b = 100; is not correct. There are following mistakes in the above expression. 1> The compiler treats the above expression as ((true) ? b = b+1 : b) = 100; // line
Note: Expressions are evaluated from left to right and assignments are made from right to left. In assignment expression, values are always assigned to a variable i.e. laft hand side must be a variable that's why the above code is wrong. 2> Now if we change the code as follows: (true) ? b = b+1 : (b = 100) ; Again this is wrong as values must be assigned to a variable.
3> Now Mr Anton Uwe has changed the code as follows int vv; vv=(true) ? (b = b + 1) : (b = 100);
The above code will still generate error. The problem is in int he expression b = b + 1;
Here b is byte , when b+1 is executed the result converted to int type and int value can not be assigned to a byte as there is a loss of precision so we need explicit type casting.
so the expression: vv=(true) ? (b = (byte)(b + 1)) : (b = 100); or vv=(true) ? b = (byte)(b + 1) : (b = 100); are correct now.
Joined: Apr 06, 2006
It is Miss Kasak Tahilramani NOT Mr Kasak Tahilramani....