Constants in C refer to fixed values that do not change during the execution of a program. C supports several types of constants as illustrated bellow:
An integer constant refers to a sequence of digits. There are three types of integers, namely decimal integer, octal integer, and hexadecimal integer.
Decimal integer consist of digits, 0 through 9, preceded by an optional – or + sign. 123 -324 0 +78 are the examples of valid decimal integer where as 15 750 20,000 $10000 are the examples of illegal numbers.
An octal integer constant consists of any combination of digits from the set 0 through 7, with a leading 0. 037 0472 0551 are the examples of octal integer.
A sequence of digits preceded by 0x or 0Xis considered as hexadecimal integer. They may also include alphabets A through F or a through f. the letter A through F represents the numbers 10 through 15. 0X2 0x93f 0Xbcd are the examples of valid hex integers.
Integer numbers are inadequate to represent quantities that vary continuously, such as distance, heights, prices and so on. These quantities are represented by numbers containing fractional part like 17.548. Such numbers are called real constants.
Single character constants
A single character constant contains a single character enclosed within a pair of single quote marks. Example of character constants are: ‘5’ ‘r’ ‘D’ ‘;’
String constantsA string constant is a sequence of characters enclosed in double quotes. The characters may be letters, numbers, special characters and blank space. Examples are: “Hello” “1989” “WELL DONE” “?...!” “5+3” “X”