Today we going to see about reason why two byte/short cannot be store in same datatype.
In general, the value assign to variable can be convert into binary format.
byte a = 5;
byte b = 4;
byte c = a + b;
The line 3 will have compile error, even though the value is smaller
The value 5 is assign to variable ‘a’, it convert to 32 byte of binary format
the value 4 is assign to variable ‘a’, it convert to 32 byte of binary format
In order to perform the basic processing of data need 32 bits as per our CPU design.
the output result data is also 32 bits, so it need 32 bits capable store datatype.
int c= a+b;