What's the use of suffix `f` on float value

前端 未结 7 597
失恋的感觉
失恋的感觉 2020-11-28 04:25

I am wondering what the difference is between these two variables in C:

float price = 3.00;

and

float price = 3.00f;
         


        
7条回答
  •  温柔的废话
    2020-11-28 05:26

    Adding few more combination of comparisons between float and double data types.

    int main()
    {
        // Double type constant(3.14) converts to Float type by 
        // truncating it's bits representation 
        float a = 3.14; 
        // Problem: float type 'a' promotes to double type and the value 
        // of 'a'  depends on how many bits added to represent it.
        if(a == 3.14)   
            std::cout<<"a: Equal"<

    Output:

     a: Not Equal
     b: Not Equal
     c: Equal
     d: Equal
    

提交回复
热议问题