When we write expressions like this in C:
bool b = 1234567890 > 09876;
What are the types of those constants? The number 1234567890
- what is its type? How does C represent it when compiling it? The C Programming Language says:
An integer constant like
1234
is anint
. Along
constant is written with a terminall
(ell) orL
, as in123456789L
; an integer constant too big to fit into anint
will also be taken as along
. Unsigned constants are written with a terminalu
orU
, and the suffixul
orUL
indicatesunsigned long
.
Floating-point constants contain a decimal point (
123.4
) or an exponent (1e-2
) or both; their type isdouble
, unless suffixed. The suffixesf
orF
indicate afloat
constant;l
orL
indicate along double
.
Here are some examples:
0 // int
0l // long
1234 // int
1234L // long
0ul // unsigned long
0u // unsigned int
2147483647 // int (just)
2147483648 // long
2147483647u // unsigned int
2147483648u // unsigned long (but could have fitted into an unsigned int)
0x0101010101010101ULL // unsigned long long
I wrote this because I felt like it. This post is my own, and not associated with my employer.
Jim. Public speaking. Friends. Vidrio.