C Basics

Constants

User Rating:  / 4
PoorBest 

The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals.

Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.

The constants are treated just like regular variables except that their values cannot be modified after their definition.

Note: - we will cover secondary Constants in sebsequent chapters.       

                  .

Rules for Constructing Constants.

  Integer

  •      An integer constant must have at least one digit.
  •      It must not have a decimal point.
  •      It can be either positive or negative.
  •      If no sign precedes an integer constant it is assumed to be positive.
  •      No commas or blanks are allowed within an integer constant.
  •      The allowable range for integer constants is -32768 to 32767.

        E.g. 426, +782, -9000, -7605

Real / Float

Real constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form.

For 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.

E.g. +325.34, 426.0 , -32.76, -48.5792

For Exponential Form

The exponential form of representation of real constants is usually used if the value of the constant is either too small or too large.

In exponential form of representation, the real constant is represented in two parts. The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’ is called exponent.

  •       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.

E.g. +3.2e-5, 4.1e8, -0.2e+3, -3.2e-5

Character Constant

  • A Character constant is a single alphabet, a single digit or a single special symbol enclosed with single quote.
  • The maximum length of a character constant can be 1 character.

E.g. 'A', 'I', '5', '=' 

 

 
 
 

                                                                                          About Us  ||  Contact Us  ||  Terms & Conditions  ||  Privacy Policy 

Referral Banners