In C Programming Language constant is an entity with fixed value, and this value does not changes throughout the execution of the program. Constant are also known as ‘Literals’. There are four basic types of constants in C Programming Language.
An integer constant can only hold integer quantity which is a sequence of whole numbers or digits.
- Integer constant can not have a decimal point or fractional part.
- Blanks and commas are not allowed within an integer constant.
- An integer constant can be either +ve or -ve.
- The constant must lie within the range of the declared data type (including qualifiers long,short etc.).
An integer constant can be either Decimal, Hexa Decimal or Octal.
A decimal integer constant consists of any combination of digits taken from the set 0 through 9. If the decimal constant contains two or more digits, the first digit can not be 0 (Zero).
12, 15, 456 etc.
An octal integer constant is a combination of digits taken from the set 0 through 7. In octal representation first digit must be a 0(Zero), in order to identify the constant as an octal number.
0, 05, 054
A hexadecimal integer constant must begin with either 0x or 0X. It can then be followed by any combination of digits taken from the set 0 through 9 and alphabets from A to F (either upper-case or lower-case are valid).
Floating Point Constants
Floating point or real constants contains a decimal point or an exponent.
- A real constant must have at least one digit each to the left and right of the decimal point.
- It can be either +ve or -ve.
- Commas and blank space are not allowed within a real constant.
A real constant can be represented in two forms: Factorial form or Exponential form.
A real constant in a fractional form must have at least one digit each to the left and right of the decimal point.
A floating-point in exponent form consists of a mantissa and an exponent.
A character constant is a single character , enclosed in single quotation marks. It can be a single alphabet, a digit or a special symbol.Maximum length of a character constant is one character.
‘A’, ‘5’, ‘$’
A string constant is sequence of characters enclosed in double quotes.It may contain letters, digits, special characters and blank space.