Why isn't “0f” treated as a floating point literal in C++?

后端 未结 6 646
暖寄归人
暖寄归人 2020-12-03 21:19

Why isn\'t 0f treated as a floating point literal in C++?

#include 

using namespace std;

int main(){
  cout << 0f <&l         


        
6条回答
  •  清歌不尽
    2020-12-03 21:49

    This isn't necessarily the only reason, but an l or L suffix can be applied to an integer literal or to a floating-point literal. 42L is of type long int; 42.0L is of type long double.

    A numeric literal with an L suffix must be disambiguated to determine whether it's integer or floating-point. Allowing an F suffix by itself to determine the type of a literal would be inconsistent and potentially confusing. It would also make it more difficult to add new suffixes in future versions of the language.

提交回复
热议问题