sandeep dhingra
,
Ranch Hand
Aug 11, 2005 15:49:00
can some one plz help me look at this byte b=2; b += 10; //1 b = b+10; //2 1. works fine but 2. does not. i know that we have to explicitly narrow the conversion in 2. by adding byte on RHS but but how come 1. works as both are one and the same thing.
Kudret Serin
,
Ranch Hand
Aug 11, 2005 16:47:00
hi sandeep, byte b=2; b += 10; //1 b = b+10; //2 1 and 2 are not same thing. 1 is identical to b=(byte) b+10; works fine. 2 does not compile because b is converted to int (due to + operator) and after adding 10, the result(int) can not be assigned to byte value.
srikanth reddy
,
Ranch Hand
Aug 11, 2005 23:01:00
hi Areca ... b=(byte)b+10;wont work ...will give loss of precision ...i think u mean to say b=(byte)(b+10)..this will work fine ..... thanks & regards srikanth
Kudret Serin
,
Ranch Hand
Aug 12, 2005 01:27:00
ha, i meaned b=(byte)(b+10) you are right. Thanks
A teeny tiny vulgar attempt to get you to buy our stuff
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com