• Post Reply Bookmark Topic Watch Topic
  • New Topic

+ operator  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to understand a particular explanation of the + operator. Can some one provide example to throw light on this?

For a + expression with two operands of primitive numeric type, the result
has a value calculated by promoting the operands to the result type and then performing the addition using that type. This might result in overflow or loss of precision.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java, meaning the compiler and runtime system, will not (I think never) tell you that an overflow might occur.
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ramya Iyer:
... Can some one provide example to throw light on this? ...


 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if the question was about "promoting the operands to the result type". See if this example makes sense:

I think these show your statement was possibly misleading. The operands are not promoted to the declared type of the result variable but to the widest operand which becomes the actual result of the expression.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Stan James:
I wonder if the question was about "promoting the operands to the result type"...


Good call. I missed that.
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!