C Programming Language
  • Home
  • C Fundamentals
    • C Character Set
    • Tokens >
      • Keywords
      • Identifiers
      • Constants >
        • Definition and Its types
        • Numeric Constants >
          • Integer Constants
          • Real Constants
        • Character Constants
        • String Constants
        • Backslash Character
      • Operators >
        • Definition and Its types
        • Arithmetic
        • Relational
        • Logical
        • Increment
        • Decrement
        • Assignment
        • Arithmetic Assignment
        • Conditional
        • Bitwise
        • Special Operators
        • Hierarchy
    • Data Types >
      • Primary (Or) Basic
      • User-Defined
      • Derived
    • Variable >
      • Definition
      • Declaration
      • Initialization
  • Control Structures
    • Decision-Control >
      • If Statement >
        • Simple-if Statement
        • if-else Statement
        • Nested-if Statement
        • if-else ladder Statement
      • Switch Statement
    • Loop Control >
      • For
      • While
      • Do-While
  • Arrays
    • Introduction
    • Single-Dimensional >
      • Definition
      • Declaration
      • Initialization
    • Two-Dimensional >
      • Definition
      • Declaration
      • Initialization
    • Multi-Dimensional >
      • Definition
      • Declaration
      • Initialization
  • Functions
    • Definition
    • Standard Library Character Functions
    • Standard Library String Functions
    • Storage Classes >
      • Definition
      • Automatic
      • Register
      • Static
      • External
  • Pointers
  • Files
    • Concepts
    • Data Files and its Categories
    • Standard Files and its Categories
  • University Questions
    • April 2001 To 2005
    • April 2006 To 2010
    • April 2011 To 2015
    • November 2001 To 2005
    • November 2006 To 2010
    • November 2011 To 2015

Constants
                         Constants in C are fixed value that does not change during the execution of a program. Constants can be of any of the basic data types. C supports several types of constants in C language as

C constants
                a.     Numeric Constants 
                                 i.      Integer Constant
                                                 1.     Decimal Integer constant
                                                 2.     Octal integer constant
                                                 3.     Hexadecimal Integer constant
                                 ii.      Real Constant

                b.     Character Constants
                                 i.      Single Character Constant
                                 ii.     String Constant

                c.      Backslash Character constants

                d.      Symbolic constants

Numeric constants:       There are two types of numeric constants,
  1. Integer constants    
  2. Real or floating-point constants

Integer constants
  • Any whole number value is an integer.
  • An integer constant refers to a sequence of digits without a decimal point.
  • An integer preceded by a unary minus may be considered to represent a negative constant
    Example:            0          -33      32767

There are three types of integer constants namely,
                a)     Decimal integer constant                     
                b)     Octal integer constant
                c)     Hexadecimal integer constant                  

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:             0          32767     -9999          -23
    Invalid:
                        12,245            -   Illegal character (,)
                        10  20  30       -   Illegal character (blank space)

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.
  • In programming, octal numbers are used.
    Valid:                   037                 0          0435
    Invalid:
                            0786               -           Illegal digit 8
                            123                 -           Does not begin with zero
                            01.2                -           Illegal character (.)

Hexadecimal integerconstant
  • It consists of any combinations of digits taken from the set 0 through 7 andalso 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.
    Valid Hexadecimal Integer Constant:            0x            0X1             0x7F           
    Invalid Hexadecimal Integer Constant:        
                                                                                0xefg  -           Illegal character g
                                                                                123     -           Does not begin with 0x

Unsigned integer constant:        An unsigned integer constant specifies only positive integer value. It is used only to count things. This constant can be identified by appending the letter u or U to the end of the constant. 

Valid:             0u          1U         65535u       0x233AU
Invalid:          -123      -         Only positive value

Long integer constant:     A long integer constant will automatically be generated simply by specifying a constant that exceeds the normal maximum value. It is used only to count things. This constant can be identified by appending the letter l or L to the end of the constant.          

Valid:             0l23456L       0x123456L    -123456l
Invalid:          0x1.2L            -           Illegal character (.)

Short integer constant:    A short integer constant specifies small integer value. This constant can be identified by appending the letter s or S to the end of the constant.

Valid:             123s                -456           32767S
Invalid:         
                        12,245                   -    Illegal character (,)
                        10  20  30  -   Illegal character (blank space)

Note: - A sign qualifier can be appended at the end of the constant. Usually suffixes(s or S, u or U, l or L) are not needed. The compiler automatically considers small integer constants to be of type short and large integer constants to be of type long.

Rules for constructing Integer constants 

i.               An integer constant must have at least one digit.
ii.              It must not have a decimal point.
iii.             It can be either positive or negative.
iv.             If no sign precedes an integer constant, it is assumed to be positive.
v.              Commas or blanks are not allowed within an integer constant.


Powered by Create your own unique website with customizable templates.