Why do you need to append an L or F after a value assigned to a C++ constant?

前端 未结 4 2107
情深已故
情深已故 2020-12-05 14:54

I have looked at quite a few places online and can\'t seem to find a good explanation as to why we should append an F or L after a value assigned to a C++ constant.

4条回答
  •  生来不讨喜
    2020-12-05 15:43

    When there is a literal value it is considered to be of a certain type. 3.0 is considered a double 3 is considered an int. 3.0F makes it in to a float instead of a double 3.0L makes it a long double instead of a double. 3L is a long int instead of an int.

    Note at least in g++, and VS08 both of your examples work just fine.

提交回复
热议问题