Constants in C
Constants are those tokens in C language whose value is fixed and does not change during the execution of a program. There are various types of constants in C.
Integer Constants
These constants refer to a sequence of digits. Any representation can be used to specify an integer constant. Table -1 shows ways to specify an integer constant, whose value is 1234 in decimal number system, in different number systems.
Table -1: Representation of an integer in different number systems
Real Constants
These constants refer to those numbers which contain fractional parts like 12.34. Such numbers are called real or floating point numbers. A real constant can also be expressed in exponential or scientific notation. As an example, 12.34 can also be expressed as 1234E-2. In this form, the real number is expressed in terms of mantissa and exponent. The mantissa is either a real number or an integer and exponent is an integer number. Both can have an optional plus or minus sign. The letter E separating the mantissa and the exponent can be written in lowercase also.
Character Constants
These constants refer to those tokens which contain a single character enclosed within a pair of single quotes like ‘W’. The character may be a letter, number, special character or blank space. As an example, ‘5’ is a character constant while as 5 is an integer constant. Similarly, 5.0 can be treated as real constant.
Character constants are printable characters which are stored in memory as their ASCII (American Standard Code for Information Interchange) code.
String Constants
These constants refer to those tokens which contain a string of characters enclosed within a pair of double quotes. The characters may be letters, numbers, special characters and blank space. Examples include “Hello World!”, “123”, and so on. It should be noted “123” is a string constant while 123 is integer constant.
Backslash Character Constants
These constants refer to those special character constants which contain a backslash and some character enclosed within a pair of single quotes. These constants are used in output functions and are known as escape sequences. Table 1 shows the list of backslash character constants along with their interpretation.
Figure -1: ASCII Table
Table -1: List of backslash character constants in C