Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can u differentiate between (1). byte b=5; int a=6; a = (int)(a+b) and (2). byte b =5; int a=6; a += b?

user-image
Question added by himanshu mittal
Date Posted: 2013/06/29
Balaji Thiagarajan
by Balaji Thiagarajan , Solutions Architect , InfinitePL

1.
byte b=5 (can hold upto127 without casting) int a=6 (all integer literals are by default int) a= a+b -> will always be int even if you dont cast it.
but b=a+b -> here you will need explicit casting like b=(byte)(a+b) 2.
byte b=5; int a=6; a+=b; -> Automatic casting done by compiler so even b+=a will compile in this case.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.