Constants in C


Constants  in  C :
C has four basic type of constants
·       Integer constants
·       Floating point constants
·       Character constants
·       String constants


Integer Constant :
        An integer constant is an integer valued number. Thus, it consist of sequence of numbers .
        Integer constants can be written in three different number system :
·       Decimal(base 10)
·       Octal(base 8)
·       Hexadecimal(base 16)
·       Binary(base 2)

A decimal integer consist of any combination of digits taken from set 0 to 9.
Example of valid decimal integer constants :
·       0
·       1
·       743
·       32767  etc.
An octal number constant can consist of digits taken from set 0 to 7.
The first digit must be 0 in order to identify the number as octal.
Examples of octal integer constants:
·       01
·       0743
·       077777   etc.
A hexa decimal integer constant must begin with either 0x or 0X .
It can be followed by any combination of digits taken from set 0 t0 9 and A to F.
Examples of hexadecimal integer constant :
·       0x
·       0X1
·       0X7FFF
·       0xabcd    etc…
The magnitude of integer constants range from zero to some maximum value.the typical max value is 32767 .
The unsigned integer constant can be identified by appending the letter U or u to the end of the constant.
Example :
·       5000U(decimal unsigned)
·       077777U(octal unsigned)
·       0X50000U(hexadecimal unsigned)
Long integer constants can be identified by letter L or l at the end of constant.
Example:
·       123456789L(decimal long)
·       0123456L(octal long)
An unsigned long integer can be identified by appending the letter UL to end of constant.
Example:
·       12345678UL(decimal unsigned long)
·       0XFFFFFUL(hexadecimal unsigned long)


Lets continue the other constant types in the next post….
Thank you ….



Previous Post
Next Post
Related Posts

0 comments:

Popular Posts