What do F and D mean at the end of numeric literals?

后端 未结 6 2050
离开以前
离开以前 2020-11-28 13:56

I\'ve seen some of this symbols, but I cannot find anything strange with it,

double d = 5D;
float f = 3.0F;

What does the D and F behind 5

6条回答
  •  醉酒成梦
    2020-11-28 14:56

    As others have mentioned they are the Type definitions, however you will less likely see i or d mentioned as these are the defaults.

    float myfloat = 0.5; 
    

    will error as the 0.5 is a double as default and you cannot autobox down from double to float (64 -> 32 bits) but

    double mydouble = 0.5;
    

    will have no problem

提交回复
热议问题