C Programming Language

Integer constants

                       Integer constants are whole numbers without any fractional part. Thus integer constants consist of a sequence of digits. Integer constants can be written in three different number systems: Decimal, Octal and Hexadecimal.

                       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 must be something other than 0. The following are valid decimal integer constants.

0                  1             1234          -786

Example:

Integer constants

The following decimal integer constants are written incorrectly for the reasons stated.

12,001               Illegal character (,).
103.0                 Illegal decimal point (.).
10 20 30           Illegal character (blank space).
045                    First digit cannot be zero.

Example:

Integer constants

                 An octal integer constant can consist any combination of digits taken from the set 0 through 7. However, the first digit must be 0, in order to identify the constant as an octal number. The following are valid octal integer constants.

0                  01            0125          0555

Example :

octal integer constant

The following decimal integer constants are written incorrectly for the reasons stated.

2010               Does not begin with 0.
2008                      Illegal digit (8).
05.10                     Illegal character (.).

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 A through F (either upper-case or lower-case). The following are valid hexadecimal integer constants.

0X0                  0x1            0XAB125          -0x555

Example:

hexadecimal integer constant

The following hexadecimal integer constants are written incorrectly for the reasons stated.

0x20.10                Illegal character (.).
02008                    Does not begins with 0x or 0X.
0xabcdefg           Illegal character (g).

Constants Home Floating-point constants

c program stats