0 ratings0% found this document useful (0 votes) 18 views4 pagesC Program
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
The C Declarations *
© baa ype
Maa
TrateDa type] | [er Deed Daw ype
Teche
‘inten
Erucraon
epteet
t
em
Hoang pia
J
> float
> double
} long doubte|
Figure2.5 Cate typos
| C-data type ean be classified as follows:
| (i) Basic Data Type:
(a) Integer (int), (b) character (char) , (C) floating point (float) , (d) double floating point
(double).
(ii) Derived Data Type: Derived data types are pointers, functions and arrays. Pointers are
in Chapter 9, functions are explained in Chapter 10 and arrays are explained in
Gili) User-defined Type: Struct, union and typedef are user-defined data types, which are
ij __ explained in Chapter 13.
|G) void Data Type: This datatype is explained in Chapter 10,
ee meEEE —
ming in C a
es egors (Gomtinued)
‘ong itogers (0 IEEE:
“ Example’ i
ye1234567
oe ni234567)
eyword, the
or Long keywo
aoe
(b) Integers Signed and Unsi Table 2.7.
and unsigned is given in
nthe signed integ
The difference betw
ned and unsigned integers
Table27 0
2 bytes in memory
Occupies
Range: 0 to 65535
Format specifier is 8u
gned int is short unsigned in
By default w
There are also long unsigned int with range 0 to
4294967295
Example:
gned long b=567898;
ned short int c=223;
When a variable is declared as unsigned the negative
range of the data type is transferred to positive, i.e.
doubles the largest size of the possible value. This is)
to declaring unsigned int; the 16 bit is free and m
used to store the sign of the number.
Brief description on these data types is given in Tabl
Table 28 Difference between signed and unsigned char
igned Character
Unsigned Character
Occupies | bytes in memory
Range: 0 to 255
Format specifier: $c
Oceupies 1 bytes in memory
Ri
ge: 128 to 127
Format specifier:
When printed using
Prints ASCIT
Cha:
puts tel format specifier, When printed using %c format specifier,
character prints ASCII character
unsigned char =\pr
Fl
oats and Doubles: Table 2.9 shows the description of floats and douby, floa
eThe C Declarations # 43
9 Difference between floating and double floating
ik Double Floating
“Float
‘Occupies 4 bytes in memory Occupies 8 bytes in memory
Range: 3 Ae~38 to 43.4048 Range: 1.7 e308 10 +1.76+308
Format string Format string: 81f
Pxample Example:
double yi
TThere also exist Long double having ranged 3.4e ~
4932 to L.le + 4932 and occupies 10 bytes in memory.
Example
long double ki
(4) _ Entire data types in C: The entire data types supported by the Cas illustrated above are given
in Table 2.10 for the convenience of the reader for understanding.
Table 210 Data types and ther control strings
Data Type Size (ytes)___Range Format String
rae 1 © 12810 127 *
1 010255 se
2 32,768 to 32,767 si or td
2 0 10 65535 su
4 -2147483648 to 2147483647 1d
4 010 4294967295 elu
4 34e-381034e+38 sf or tg
8 17-3080 1.7 €+ 308 ale
10 34esoa2tole+4932 SE
wt a 32768 to 32767 aa
~The sine may vary according to the numberof variables used with enum datatype,
2.12 INTEGER AND FLOAT NUMBER REPRESENTATIONS
2.12.1 | Integer Representation
Recall that an integer with sign is called a signed integer. The signed integer hes signs positive
or negative. The signs are represented in the computer in the binary format as | for ~ (minus)
oi for + (plus) or vibelrerin. The sign bits aivopyeetee oy Taupe (EGS) ) ie of
storing the signed number, system reserves the leftmost bit for the representation of the sign
of the number.
For example, positive signed numbel
form. In this form, the sign is represented by
binary form.
+7 is represented as 0 0000111
15 are represented in the form called signed magnitude
yy a binary 0 and the remaining magnitude by equivalentSe
44 ¢ Programming in C
‘The signed negative integers can be represented in any one of the following forms:
(a) signed—magnitude form
(6) signed—t’s complement form
(©) signed—2’s complement form
In the signed magnitude form, the sign of the number is represented as 1 and the magnitude
lent binary form.
Example:
Tis represented as 1 0000111
In the signed 1's complement form, the sign of the integer is indicated by
shown in 1’s complement form as follows,
7 is represented as 1 1111000
1 and the m
ment form as follows,
~1 is represented by 1 1111001
2.12.2 | Floating-Point Representation
In most of the applications, fractions are often used. The system of the number represen
keeps track of the position of binary and decimal point is better than the fixed-point repre
“ -point representation.
a a fractional part, The real number is a
ers are either positive or negative. The re 4.4
or A545 % 10°. This type of Bee soiicon ee a
‘this scientific form, any number can be expressed as cor
we can say the number ‘n’ can be expressed as n=mre
of the number system and e is the exponent. Mantissa is
s the position of the binary or decimal point. For €
indicates the plus sign,
Most of the computers