Constants in C-Language

The Alphabets, numbers and special symbols when properly combined from constants and variables.
A ‘constant’ is a quantity that does not change. this quantity can be stored at a location in the memory of the Computer.
A ‘variable’ can be considered as a given name to the location in memory where this constant is stored. Naturally the contents of the variable can change.
For example in the equation: 3X+Y=20,
Since 3 and 20 can’t change, they are called constants. Whereas the quantities X and Y can vary or change hence are called variable.

C Constant

At this stage we would restricts our discussion to the more commonly used constants. Like characters, integer, float, logical, and string constants. Let us see the details of each of these constants. For constructing these different types of constants certain rules have been laid down. These rules are as under:

Rules for Constructing Integer:

a) An integer constant must have at least one digit.
b) It must not have a decimal point.
c) It could be either positive or negative.
d) If no sign precedes an integer constant it is assume to be positive.
e) No commas or blanks allow within the integer constant.
f) The allowable range for integer constants is -332768 to +32767.

Integer constants must fall within this range. Because the IBM compatible microcomputers are usually 16 bit computers. Which can not support a number falling outside the above mentioned range. For a 32 bit Computer of course the range may be much larger.
Ex.: 426
+782
-8000
-7605

Rules For Constructing Real Constants:

Real constants are often called Floating Point constants. The real constants could be written in two forms, Fractional form or 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 blank are allowed within a real constant.

Ex.: 426.0
+325.34
-32.76
-48.5792

The Exponential form representation of real constants is usually used if the value of the constants is either too small or too large. The real constant is represents in two parts. The part appearing before ‘e’ call exponent. In place of a small case ‘e’ a capital ‘E ‘ can also be used.

Following rules must be observed while construction of Real Constants expressed in exponential form:

a) The mantissa part and the exponent part separated by a letter ‘e’.
b) The mantissa part may have positive or negative signs.
c) Default sign of mantissa is part is positive.
d) The exponent must have at least one digit which must be a positive or a negative integer. Default sign is positive.
e) Range of real constants expressed om exponential form is -3.4e38 to 3.4e38.

Ex.: +3.2e-5
4.1e8
-0.2e+3
-3.2e-5

Rules for Constructing Character Constants

a) A character constant is either a single alphabet, a single digit ora single special symbol enclosed within a pair of 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 2 character. Ex. ‘A’ ‘I’ ‘5’ c) The valid range of character constant is -128 to +127. It appear as surprising that the character constant should have a numeric range. But this fact can be appreciated once we understand that character and integer constants are often used interchangeably.

Logical Constants

A logical constant can take either of two values: truth or falsity. In C a non-zero value is always treated as truth whereas a zero is treated as a falsity. Hence values like 32, -45, 3,12 etc. treats as a logical constant with false value. The logical constants are very useful in evaluating logical expressions and complex conditions.

String Constants

A collection of character enclosed within a pair of double inverted commas in treated as a string constant.
Ex.: “Hello”
“44-A, Gokulpeth, Nagpur”
“34.567”
In the above example though 34.567 appears to be real constant.Once it is enclose within inverted commas there onwards it treat as a string constant. Though not shown explicitly in the above examples each string constant always ends with a terminator. Using this fact we can find out where a string ends. The string of characters use in a string constant are always store in the adjacent memory locations. See this arrangement in the figure below.

FOR MORE HELP

CONTACT US

VISIT

TeamSOFTLINE777

Related Posts