K
karthik
Hi,
Code snippet:
1. byte a=1,b=2;
2. byte c = a & b;
Line No.2 is a compile time error. It needs a type casting to byte.
This will work fine: byte c = (int) (a&b)
However this is not a compile time error, working perfectly fine: byte
c = 1 & 2;
Same is applicale for Modulo operator too.
Simple inference from this is, auto type conversion (to integer) for
such operations [bit AND, Modulo] takes place for vales stored
variables. But not for direct literal values.
Anybody knows about this, the actual reason??
Code snippet:
1. byte a=1,b=2;
2. byte c = a & b;
Line No.2 is a compile time error. It needs a type casting to byte.
This will work fine: byte c = (int) (a&b)
However this is not a compile time error, working perfectly fine: byte
c = 1 & 2;
Same is applicale for Modulo operator too.
Simple inference from this is, auto type conversion (to integer) for
such operations [bit AND, Modulo] takes place for vales stored
variables. But not for direct literal values.
Anybody knows about this, the actual reason??