Header Ads

Integer and Float Conversion


Integer and Float Conversion

Integer and Float conversion

In order to effectively develop C program, it will be necessary to
understand the rules that are used for the implicit conversion of
floating point and integer values in C. These are mentioned below.
Note them carefully:

  1. An arithmetic operation between an integer and integer
    always yields an integer result.
  2. An operation between a real and real always yields a real
    result.
  3. An operation between an integer and real always yields a real
    result. In this operation the integer is first promoted to real
    and then the operation is performed. Hence the result is real.

  4. I think a few practical examples shown below would put the
    issue beyond doubt.


    OperationResult
    5 / 22
    5.0 / 22.500000
    5 / 2.02.500000
    5.0 / 2.02.500000
    2 / 50
    2.0 / 50.400000
    2 / 5.00.400000
    2.0 / 5.00.400000

No comments