How does the compiler know which type will be returned

This article says:

If I write such a line inside the function:, return 1.4it is obvious to me and the compiler that the function returns double .

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

+4
source share
5 answers

No, 1.4- double. floatis written as1.4f

75         // int
75u        // unsigned int
75l        // long
75ul       // unsigned long 
75lu       // unsigned long

3.14159L   // long double
6.02e23f   // float  

Source

+3
source

1.4is a doubleliteral, unlike a floatliteral 1.4fand a long doubleliteral 1.4l.

, .

+3

, auto return type, - , .

: 1.4 double, float long double, double . , .

+2

1.4 ( ) double. float, 1.4f, long double - 1.4L.

+1

1.4 double, double.

float 1.4f

1.4L

1.4  // double
1.4f // float
1.4L // long double
+1

Source: https://habr.com/ru/post/1622331/


All Articles