Вы находитесь на странице: 1из 2

CONSTANTS IN “C”

A Constant is a value which does not change during the course of execution of a
program.

Numeric Constants-
Numeric constants contain only numeric data. There are basically 2 types of
numeric constants:
(i) Integer Constant
(ii) Real Constant

(i) Integer Constant - Integer constants are those constants which neither
have a decimal point nor an exponent. They may be preceded by plus or
minus sign. Ex: 100000 but 1, 00,000 is invalid.
Types of Integer Constant-
(a) Decimal Integer Constant
(b) Octal Integer Constant
(c) Hexadecimal Integer Constant

(a) Decimal integers consists of a set of digits, 0 through 9, preceded by


an optional + or – sign. Ex: 123,-321,0,+84
Spaces, commas & non-digit characters are not permitted between
digits.
(b) Octal integers consist of any combination of digits from 0 to 7, with a
leading zero. Ex: 037,001,0435,0
(c) Hexadecimal integers consist of digits from 0 to 9 as well as letters
from A to F. Each hexadecimal integer is preceded by zeroX (0X). Ex:
0X2, 0X8D, 0Xbcd.
(ii) Real Constant - Real constants are those constants which contain digits
from 0 to 9, a decimal point and an exponent, preceded by plus or minus
sign. It is also called floating point number because decimal points can be
shifted and exponent can be approximated. The general form is
Mantissa e exponent
Ex: 0.0083, -0.75, 495.36, +247.00, 0.65e4, 12e-2

Non-Numeric Constants-
Non-numeric constants contain both numeric as well as non-numeric data, but
arithmetic operations cannot be applied on numeric constants in this case. Basically there
are 2 types of non-numeric constants:
(i) Single Character Constant
(ii) String Constant

(i) Single Character Constants - These are single characters enclosed within
single quotes. Ex: ‘A’, ‘b’, ‘ ’, ‘8’ etc.
(ii) String Constants - These are the collection of characters enclosed within
double quotes. Ex: “STRING”, “Delhi”, “1982” etc.

Вам также может понравиться