The value are assigned to each constant variables are referred to as the literals. Literals are represent the fixed values that cannot be modified. Literals are also contains memory but does not have references as variables.
For example :-
“const int= 15;” is a constant expression and the value of 15 are referred to as constant integer literal.
Types of literals:
There are four types of literals in C
Integer literal: There are used to store and represent the integer value. It is represents the value neither in fractional nor exponential part.
The integer literal are specified in three ways
Decimal number(base 10): It is defined to represent the digits between 0 to 9. For examples- 78,29
Octal number(base 8): A zero followed by zero or more octal digits(0,1,2,3,4,5,6,7). For examples- 038, 025 etc.
Hexadecimal number(base 16): It is defined a number in which 0x and 0X is followed by the hexadecimal digits. For examples- Digits from 0 to 9 alphabetical characters from (a-z) or (A-Z).
It’s a simple example of integer literal
const int a=24; //constant integer literal
printf("Integer literal : %d",a);
Integer literal : 24
Float-point literal: The floating-point literals can be stored either in decimal form or exponential form. Floating-point.Decimals one must keep two things in mind to produce valid literals :
In the decimal form,one must include the exponent part, decimal point or both otherwise it lead to an error.
In the exponential form one must include the fractional part, integer part or both otherwise it will lead to an error. It’s a simple example of floating-point literal
const float a =4.5;
printf("floating point literal :%f",a);
Character literal: A character literal contains a single character together within single quotes.If you can assigned multiple character to the variable then we need to create a character array.Storing more than one character within a single quotes then they will show a warning and display the last character of the literal.Representation of character literal:
It can be represented a single character within single quotes. For Example: ‘a’,’n’, etc.
Escape sequence character within single quotes to represent a character literal.For Example: ‘\n’,’b’, etc.
We are also used the ASCII in integer to represent a character literal. For Example: ascii value is : 65 is ‘A’.
String literal: A string literal is similar to the character literal except it can store multiple character and uses a double quotes.It can also contain an additional character which get automatically inserted.We can also use the ‘+’ symbol to concatenate two strings.