Types of C Constants
C constants can be divided into two major categories:
(a)Primary Constants
(b)Secondary Constants
These constants are further categorized as shown in Figure 1.4.
At this stage we would restrict our discussion to only Primary
Constants, namely, Integer, Real and Character 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:
(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.
Truly speaking the range of an Integer constant depends upon
the compiler. For a 16-bit compiler like Turbo C or Turbo C++ the range is
–32768 to 32767. For a 32-bit compiler the range would be even greater. Question
like what exactly do you mean by a 16-bit or a 32-bit compiler, what range of an
Integer constant has to do with the type of compiler and such questions are
discussed in detail in Chapter 16. Till that time it would be assumed that we
are working with a 16-bit compiler.
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 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.
(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.
+325.34
426.0
-32.76
-48.5792
The exponential form of representation of real constants is
usually used if the value of the constant is either too small or too large. It
however doesn’t restrict us in any way from using exponential form of
representation for other real constants.
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. Following rules must be
observed while constructing real constants expressed in exponential form:
(a) The mantissa part and the exponential part should be
separated by a letter e.
(b) The mantissa part may have a positive or negative sign.
(c) Default sign of mantissa part is positive.
(d) The exponent must have at least one digit, which must be a positive or negative integer. Default sign is positive.
(e) Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.
(b) The mantissa part may have a positive or negative sign.
(c) Default sign of mantissa part is positive.
(d) The exponent must have at least one digit, which must be a positive or negative integer. Default sign is positive.
(e) Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.
Ex.:
+3.2e-5
4.1e8
-0.2e+3
-3.2e-5
4.1e8
-0.2e+3
-3.2e-5
Next topic : Let us C chapter 1 GETTING STARTED (part 4)
Previous topic : Let us C chapter 1 GETTING STARTED (part 2)
Full book : All Topics
Please, don’t forget to subscribe to our fantastic RSS feed free newsletter, join Dbstudies community on Facebook! If you enjoyed our posts we humbly ask you to comment, and help us spread the word!
0 Comments:
Post a Comment