Machine-translated by Google. Questions are authored in English.
Top

Discussion

The rule for implicit type conversion is

  • A.int < unsigned < float < double
  • B.unsigned < int < float < double
  • C.int < unsigned < double < float
  • D.unsigned < inc < double < float

Answer: A

Correct answer: int < unsigned < float < double

The usual arithmetic conversions promote towards the type of greater rank, and the order is int, unsigned, float, double.

The int to unsigned step is the one that causes real trouble: comparing a negative int with an unsigned converts the negative value to a large positive one, so -1 < 1u evaluates false. The floating point steps are safer, though converting a large integer to float can lose precision silently.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.