Exforsys
+ Reply to Thread
Results 1 to 7 of 7

Integer or Float... Not Clear!!!!!

This is a discussion on Integer or Float... Not Clear!!!!! within the C and C++ forums, part of the Programming Talk category; Hi All, I have an integer value and a float value and if I perform arithmetic operation between the values ...

  1. #1
    Allan is offline Member Array
    Join Date
    May 2006
    Answers
    40

    Integer or Float... Not Clear!!!!!

    Hi All,
    I have an integer value and a float value and if I perform arithmetic operation between the values what would be the result? Will it be an integer value or a float value?

    Regards,
    Allan


  2. #2
    blenda is offline Member Array
    Join Date
    May 2006
    Answers
    36
    Hi,
    I have not thought of this operation which is very common occurrence in any mathematical calculation. So it is essential to know the answer for the same. I could not figure out the answer but while searching answer for this question one more related question cam to my mind and it is what would be the result of if we assign a float value to a integer what would be the result will it be a float or a integer? Someone answer the related question along with the previous one.
    Regards,
    Blenda


  3. #3
    norman is offline Member Array
    Join Date
    May 2006
    Answers
    43
    Hi,
    I know that arithmetic operation between integer and integer results in integer and similarly arithmetic operation between float and float results in float. But this question is interesting and kindly someone let us know the answer for the same.

    Regards,
    Norman


  4. #4
    norman is offline Member Array
    Join Date
    May 2006
    Answers
    43
    Hi,
    The answer for all the questions and queries posted in this section will help to get an insight on Integer and Float conversions and handling of numeric data types in C program. The answer to the first question is arithmetic operation between integers and float results in always float and the answer to the second question is assigning a float value to an integer gives an integer result.

    Regards,
    Norman


  5. #5
    blenda is offline Member Array
    Join Date
    May 2006
    Answers
    36
    Hi,
    Having known the answer from Norman if someone wants to get the explanation for the same read the following:
    The arithmetic operation between integer and float results as always float because integer first gets converted into float and then operation is carried out. So operation between float and float results in always float. When a float value is assigned to a integer it is converted as integer because left side assignment variable is of type integer and hence result is a integer.

    Regards,
    Blenda


  6. #6
    devsuv is offline Junior Member Array
    Join Date
    Jun 2006
    Answers
    2
    Quote Originally Posted by Allan
    Hi All,
    I have an integer value and a float value and if I perform arithmetic operation between the values what would be the result? Will it be an integer value or a float value?

    Regards,
    Allan
    that will be float.if u r collecting thease value in a int then it ll be casted to int


  7. #7
    blenda is offline Member Array
    Join Date
    May 2006
    Answers
    36
    Hi,
    But one thing that must be taken care is when float is casted into integer it losses data and so one must ensure the need of such a result.

    Blenda


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...