Constants : Integer constants

 

Tokens in C

To creating a program in C the most important element are Tokens in C. The token is the smallest individual element in C.

 


Figure: C tokens

Constants:-

Constants in C are fixed value that does not change during the execution of a program.


Figure: Constants

Numeric constants:

Numeric constants have two types.

  1. Integer constants    
  2. Real or floating-point constants

1. Integer constants

  • It is whole number value.
  • It is a sequence of digits without a decimal point.

Integer constants are divided in three types namely,
                a)     Decimal integer constant                     
                b)     Octal integer constant
                c)     Hexadecimal integer constant                  

a) Decimal Integer constant (base 10)   

  • It consists of any combinations of digits taken from the set 0 through 9, preceded by an optional – or + sign.
  • The first digit must be other than 0.
  • Embedded spaces, commas, and non-digit characters are not permitted between digits.

    Valid:             1          4356     -77777          -23
    Invalid:         4,579            -   Illegal character (,)
                        40  33  46       -   Illegal character (blank space)

b) Octal Integer Constant (base 8)

  • It consists of any combinations of digits taken from the set 0 through 7.
  • If a constant contains two or more digits, the first digit must be 0.

    Valid:                   045           0          0654
    Invalid:           084               -           Illegal digit 8
                            356                 -           Does not begin with zero
                            22.7                -           Illegal character (.)

c) Hexadecimal integer constant

  • It consists of any combinations of digits taken from the set 0 through 9 and also A through F (either uppercase or lowercase).
  • The letters a through f (or A through F) represent the decimal quantities 10 through 15 respectively.
  • This constant must begin with either 0x or 0X.
  • In programming, hexadecimal numbers are used.

1.      Valid Hexadecimal Integer Constant:            0x            0X6             0x3C           
Invalid Hexadecimal Integer Constant:       0xfh  -           Illegal character h
                                                                      45     -           Does not begin with 0x


 

Decimal

Octal

Hexadecimal

Numbers Use

0,1,2,3,4,5,6,7,8,9

0,1,2,3,4,5,6,7

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

First number

Non Zero

0

ox



Rules for constructing Integer constants 

1) An integer constant must have at least one digit.
2)  It must not have a decimal point.
3) It can be either positive or negative.

4) If no sign before an integer constant, it is assumed to be positive.
5) Commas or blanks are not allowed within an integer constant.


Post a Comment

0 Comments