Search code examples
c++c++14autotype-deduction

How does the compiler know which type to return


This article says:

If I write a line of code like this inside a function: return 1.4, It is obvious to both me and the compiler that the function is returning a double.

It is not obvious to me: the return type could be a float, a double, or a long double. How does the compiler choose between the 3 types?


Solution

  • No, 1.4 is a double. float is written as 1.4f

    75         // int
    75u        // unsigned int
    75l        // long
    75ul       // unsigned long 
    75lu       // unsigned long
    
    3.14159L   // long double
    6.02e23f   // float  
    

    Source