Integer Literals
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, 78
b. Octal-literal(base 8): a 0 followed by zero or more octal digits(0, 1, 2, 3, 4, 5, 6, 7).
Example:
045, 076, 06210
c. 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, 0xFEA
d. Binary-literal(base 2): 0b or 0B followed by one or more binary digits(0, 1).
Example:
0b101, 0B111
B) Suffixes: The Prefix 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.
- int: No suffix is required because integer constant is by default assigned as an int data type.
- unsigned int: character u or U at the end of an integer constant.
- long int: character l or L at the end of an integer constant.
- unsigned long int: character ul or UL at the end of an integer constant.
- long long int: character ll or LL at the end of an integer constant.
- unsigned long long int: character ull or ULL at the end of an integer constant.
Example:
C
#include <stdio.h> int main() { // constant integer literal const int intVal = 10; printf ( "Integer Literal:%d \n" , intVal); return 0; } |
Integer Literal:10
Literals in C
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.