type casting

##### Title

##### Question

In assignment question,

i can understand typecasting of given expression but what is the meaning of real division in type casting?

C-and-Cpp Increment-And-Decrement-Operators 11-12 min 50-60 sec

__Answers:__

When you divide say 5 by 4, the result depends on whether you are talking about integer division of real division. In integer division, the answer is 1 (quotient). In real division, the answer is 1.25.

If you are expecting a floating point value as your answer, either the numerator or denominator should be float. If both are integer, the result will be in integer. The fractional part will be truncated.

eg. 5/2=2

and 5/2.0=2.5 or 5.0/2=2.5 (example for implicit type casting - if one of the number is float, the answer will be in float)

(float)5/2=2.5(example for explicit type conversion)

Login to add comment