Thursday 15 July 2010

Use of trailing characters in JAVA/C++ -


I was a little curious why we use characters in Java / C ++ . E.g.,

  float F = 23f;   

We can also write

  float f = 23;   

Both have the effect.

This is important when you have rigorous numbers in mathematical operations.

For example:

  5/2 == 2 5.0f / 2.0f = 2.5f 5.0 / 2.0 = 2.5 / You doubles in the suffix of 'F' Doubles for 5.0d / 2.0d = 2.5d // can also be used as "D"   

Apart from this, there will be a different result:

  blah / 3.141592653592 // This gives a precise double blah / 3.141592653592 F / returns it gives a less precise float    

No comments:

Post a Comment