Thursday, 16 September 2010

08. COSNTANTS

There are four basic types of constants in C. They are integer constants, floating-point constants, character constants and string constants (there are also enumeration constants). Moreover, there are several different kinds of integer and floating-point constants, as discussed below.
  Integer and floating-point constants represent numbers, They are often referred to collectively as numeric-type constants. The following rules apply to all numeric-type constants.

1. Commas and blank space cannot be included within the constant.

2. The constant can be preceded by a minus (-) sign if desired.

3. The value of a constant cannot exceed specified minimum and maximum bounds. For each type of constant, these bounds will vary from one C compiler to another.


Integer Constants : 

  An integer constant is an integer-valued number. Thus it consists of a sequence of digits. Integer constants can be written in three different number systems: decimal (base 10), octal (base 8) and hexadecimal (base 16).Beginning programmers rarely, however, use anything other than decimal integer constants.
  A decimal integer constant can consist of any combination of digits taken from the set 0 through 9. If the constant contains two or more digits, the first digit must be something other than 0.

For example : 0      1       743   5280   32767   9999
They all are valid decimal integer constants.

Note that : you can not use any coma(,), any fullstops (.), Bland space( ), and can not use first number zero (0998).

  An octal integer constant can consist of 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 .

For example:  0    01   0743    0774
They all are valid octal decimal integer constants.

In a octal constants you does not begin with 0, can not use ( . ) .

   A hexadecimal integer constant must begin with either  0x or 0X. It can then be followed by any combination of digits taken from the sets 0 through 9 and a through f  (either upper-or lowercase). note that the letters a through f (or A through F) represent the (decimal )quantities 10 through 15, respectively. 

 For example: 0x   0xbb7    0x7ddd  0xabcd
They all are valid hexadecimal integer constants.

 

No comments:

Post a Comment