![]() |
VOOZH | about |
In C, Literals are the constant values that are assigned to the variables. Literals represent fixed values that cannot be modified. Literals contain memory but they do not have references as variables. Generally, both terms, constants, and literals are used interchangeably.
For example, “const int = 5;“, is a constant expression and the value 5 is referred to as a constant integer literal.
There are 4 types of literal in C:
Integer literals are used to represent and store the integer values only. Integer literals are expressed in two types i.e.
A) Prefixes: The Prefix of the integer literal indicates the base in which it is to be read.
For Example:
0x10 = 16
Because 0x prefix represents a HexaDecimal base. So 10 in HexaDecimal is 16 in Decimal. Hence the value 16.
There are basically represented into 4 types:
a. Decimal-literal(base 10): A non-zero decimal digit followed by zero or more decimal digits(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).
Example:
56, 78b. Octal-literal(base 8): a 0 followed by zero or more octal digits(0, 1, 2, 3, 4, 5, 6, 7).
Example:
045, 076, 06210c. Hex-literal(base 16):0x or 0X followed by one or more hexadecimal digits(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, A, b, B, c, C, d, D, e, E, f, F).
Example:
0x23A, 0Xb4C, 0xFEAd. Binary-literal(base 2):0b or 0B followed by one or more binary digits(0, 1).
Example:
0b101, 0B111B) Suffixes: The Suffixes of the integer literal indicates the type in which it is to be read.
For example:
12345678901234LL
indicates a long long integer value 12345678901234 because of the suffix LL
These are represented in many ways according to their data types.
12 10
Valid Floating Literals:
10.125
1.215e-10L
10.5E-3
Invalid Floating Literals:
123E
1250f
0.e879
Floating point literal: 4.14
Character Literal: A
: There are various special characters that one can use to perform various operations.
Welcome To Geeks For Geeks
Must Read: