Much like variables, literals may be qualified to force the compiler to treat them as a specific data type.
Qualifiers are specified by adding a suffix to the value:
- U or u for unsigned: 25u
- L (preferred) or l for long: 25L
- F or f for float: 10f or 10.25f
The U and L suffixes may be combined to create an unsigned long literal: 0xF5UL, but U must always precede L.
Why Are Qualifiers Needed?
Integers without a suffix are assumed to be signed and short. This has some implications with respect to arithmetic operations that will be discussed throughout the section on operators.
Also, a number like 10 will be interpreted as an integer. However, in some arithmetic expressions it may be necessary to force the compiler to treat it as a floating-point value to get the desired result.