Friday, 18 January 2013

Constants


A constant is an entity that doesn’t change whereas a variable is an entity that may change.

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

Rules for Constructing Real/Float Constants
Real constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form.
Following rules must be observed while constructing real constants expressed in fractional form:
a)      A real constant must have at least one digit.
b)      It must have a decimal point.
c)      It could be either positive or negative.
d)      Default sign is positive.
e)      No commas or blanks are allowed within a real constant.

Ex.: +630.58
76.0
-81.36
-12.6732

Rules for Constructing Character Constants
a)      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. For example, ’A’ is a valid character constant whereas ‘A’ is not.
b)      The maximum length of a character constant can be 1 character.

e.g..: 'A'
'D'
'7'
'=' 

1 comment: