Constant is a quantity in C whose
value does not change ever. This quantity stored in memory at any certain
location of Computer. There are mostly two type of constant which are given
below.
- Primary Constant
- Secondary Constant
These constant are further
categorized as shown in figure
But at this stage our focus will
we on Primary Constants, namely Numeric
and Character Constants.
Rules For Constructing Integers
Constants
An integer constant means a
sequence of digit. There are three type of Integer constant which are decimal
integers, octal integer and hexadecimal integer.
Decimal integers contain digit from
0 to 9 with optional sign – or + which indicate that number is positive or
negative. Valid set of decimal integers
are
+ 123, 123, 456, -34, -542, 0,
76543
While space, commas, and non-digit
characters are not entertained between digits. For example –
15-234, 23,000, 43 434, $3454
are illegal numbers.
- An integer constant must at least one digit.
- Decimal point must not be allowed
- Number could be positive or negative.
- If no sign used before number, it means integer Constant assumed to be positive.
- No comma, blank space, and dollar sign must within or before an integer constant.
Integer Constant have range
limitation which vary according machine. If you working 16 bit computer ,
integer constant range will vary between -32768 to +32767
Rules For Constructing Real
Constants
Integer constant are unable to
calculate measurement problem and cost estimated problem because these
quantities are represented by number
containing fraction part like 13.456. this numbers are called real number or
floating points number
For example –
23.54554, -544534.56546,
+45345.5534
Floating points number or real
Constant are those number that contain decimal points between digits but
remember point will be between digit not before neither after like .43 or 4343.
Valid
|
Invalid
|
443.4434, -434.546, +55.54
|
.4545, -.5345, 45354. , -53454.
|
- A real number must be at least two digit with one decimal point.
- It could be either positive or negative.
- Default sign assumed positive.
- No comma, blank space are allowed between number except decimal point.
There are another way to represent
real number is exponential notation or scientific notation. In this type of
notation two part exist that joined with e character. Like 32.334e2
First part of this notation is
called mantissa and second part of this notation called exponent. This method
of real number we will descius in last chapter.
Rules For Constructing Character
Constants
Character constant is a single
character from character set of C that enclosed by single quote marks. Examples
of character constant are
‘5’ ‘a’ ‘;’ ‘
’
Maximum length of character
constant must be 1 with enclosed by single quote.
Above ‘5’ is character constant and
it is not equal to 5 because 5 is digit and ‘5’ is character constant. Every character constants have integer value
known as ASCII values. ‘5’ integer value is 53 and integer value of ‘a’ is 97.
There are many discussion are remaining
on this section we will later in Next related Section
Rules for Constructing String
Constant
A string constant is sequence of
character that enclosed by double quotes. This character may be numbers,
alphabets and special symbols and also blank space. Example are
“How are you” “1988” “WELL DONE” “?
$%^%$#” “3+4=7”
There you should mind that
character constant is not equivalent to string constant example (“x” is not
equivalent to ‘x’)
- String Constant should be enclosed with double quotes.
- String Constant contains all digit, special symbols and alphabets.
- String constant contain blank space.
Backslash Character Constants
There is special character
constants that used with output function in C. every Backslash character
constant used with specific reason during outputting. For example, the symbol ‘\n’
stands here for newline character that tells signal to computer print new line
after this ‘\n’ new line symbol.
No comments:
Write comments