Tuesday 2 September 2014

Rules for Constructing Character Constants


  • A character constant is a single alphabet, a single digit or a single special symbol enclosed within single inverted commas.
  • Both the inverted commas should point to the left. 

Example:
                  ’A’ is a valid character constant whereas ‘A’ is not.

The maximum length of a character constant can be 1 character.
Example:
                   'A'
                   'I'
                   '5'
                   '='

Rules for Constructing Real Constants

Real constants are often called Floating Point constants. The real constants could be written in two forms.

  1. Fractional form
  2. Exponential form.
Fractional form:


  • A real constant must have at least one digit.
  • It must have a decimal point.
  • It could be either positive or negative.
  • Default sign is positive.
  • No commas or blanks are allowed within a real constant.


Ex:
      +235.33
        516.0
       -34.73
       -36.5789

Exponential form:
  • The mantissa part and the exponential part should be separated by a letter e.
  • The mantissa part may have a positive or negative sign.
  • Default sign of mantissa part is positive.
  • The exponent must have at least one digit, which must be a positive or negative integer. Default sign is positive.
  • Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.

Ex:
       +2.3e-5
         5.1e5
       -0.2e+4
       -3.5e-4

Rules for Constructing Integer Constants

An integer constant must have at least one digit.

  1. It must not have a decimal point.
  2. It can be either positive or negative.
  3. If no sign precedes an integer constant it is assumed to be positive.
  4. No commas or blanks are allowed within an integer constant.
  5. The allowable range for integer constants is -32768 to 32767.


Ex:
      326, +682, -7000, -5604

Types of C Constants

C constants can be divided into two major categories:

1.Primary Constants
2.Secondary Constants

Primary Constants:

    1. Integer Constant
    2. Real Constant
    3. Character Constant

Secondary Constants:

    1. Array
    2. Pointer
    3. Structure
    4. Union
    5. Enum,Etc....

The C Character Set

A character denotes any alphabet, digit or special symbol used to represent information.

Alphabets : 
                  A, B, ….., Y, Z
                  a, b, ……, y, z

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

Special symbols:
                   ~ ‘ ! @ # % ^ & * ( ) _ - + = | \ { }[ ] : ; " ' < > , . ? /

What is C

C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. In the late seventies C began to replace the more familiar languages of that time like PL/I, ALGOL, etc. No one pushed C. It wasn’t made the ‘official’ Bell Labs language. Thus, without any advertisement C’s reputation spread and its pool of users grew. Ritchie seems to have been rather surprised that so many programmers preferred C to older languages like FORTRAN or PL/I, or the newer ones like Pascal and APL. But, that's what happened.