How 3 and 3.0 are equal plz explain

Discussion in 'C Programming' started by manish sahu, Aug 18, 2009.

  1. manish sahu

    manish sahu Guest

    what would be the output


    op is HI
    how 3==3.0 plz Explain
    manish sahu, Aug 18, 2009
    1. Advertisements

  2. manish sahu

    david Guest

    It's hard to explain, try for a better answer
    david, Aug 18, 2009
    1. Advertisements

  3. manish sahu

    Tim Prince Guest

    If your C textbook doesn't explain how 3==3.0 is equivalent to
    (double)3 == 3.0
    you need a better textbook.
    I would prefer that a C textbook would explain questions such as when
    such casts are exact, but that preference does go beyond reality.
    Tim Prince, Aug 18, 2009
  4. it depends on the axiomisations you choose for integers and reals
    Nick Keighley, Aug 19, 2009
  5. manish sahu

    Thad Smith Guest

    C compares values. The two constants have the same value when compared.
    Thad Smith, Aug 21, 2009
  6. Well, they have different types. Specifically, 3 is of type int, and
    3.0 is of type double. The standard specifies rules for converting
    operands of "==" to a common type. In this case, the value 3 is
    converted from int to double, and the result if this conversion is
    compared to 3.0. Converting the int value 3 to double will almost
    certainly yield the value 3.0, though I don't think the standard
    quite guarantees it.
    Keith Thompson, Aug 21, 2009
  7. manish sahu

    Ruturaj Pansare

    Aug 16, 2017
    Likes Received:

    Well it must be int something say x=3 and something float sat y=3.0 In C when there is an operation between an int and a float ,the int is converted into float.In this example 3 is converted to 3.0 and then the comparison is made.Hence 3 == 3.0.Hope this works!
    Ruturaj Pansare, Aug 16, 2017
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.