Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 392
qdii Avatar asked Dec 24 '22 11:12

qdii


1 Answers

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

like image 193
Humam Helfawi Avatar answered Feb 14 '23 20:02

Humam Helfawi