• Post Reply Bookmark Topic Watch Topic
  • New Topic

byte data type  RSS feed

 
Ela Jha
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
byte b=4; //valid
byte c=5; //vaild
byte d= b+c; //is invalid
Pls explain why though the range of byte is -128 to 127
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all integer mathematics will result in an int being returned unless you explicitly cast it to something else.
So your last statement tries to assign an int value to a byte variable, where of course it won't fit.
 
Ela Jha
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got it,thanks Jeroen.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!