This preview shows page 1. Sign up to view the full content.
Unformatted text preview: loating point ty pes are c ons is tent and don't have this problem). For
ex erc is es in this c las s , we c an as s ume that ints are 32-bits . The interes ted reader c an als o learn about a header
< intty pes .h> , whic h provides a s et of ty pes that are guaranteed to be c ons is tent ac ros s platforms . float
The floa t data ty pe allows y ou to s tore floating point numbers whic h the int data ty pe c annot handle. Remember the IEEE 754
floating point repres entation of numbers ? floa t denotes the 32-bit, s ingle prec is ion format, whic h has a range of -3.4 × 1038 to + 3.4
× 1038. Many real world c omputations res ult in a floating point res ult. If y ou us e the int data ty pe to hold s uc h res ults , y ou will not
get ac c urate ans wers . This is bec aus e the int data ty pe trunc ates every thing after the dec imal pos ition. So if y our ans wer is 3.14
and y ou try to hold this in a variable defined as int, y ou will get 3 as y our ans wer. The 0.14 part will be trunc ated thereby res ulting in
inac c urate res ults . char
This is an 8-bit s igned integer (range -128 to 127) whic h is ty pic ally us ed to s tore s imple c harac ters that are available in the ASCII
table. All the c harac ters that c an be repres ented as an ASCII number c an be s tored in the cha r data ty pe. bool
Many times , it is required that y our program behaves lik e a s witc h. It is important in thes e s ituations that y our program gives either
a ye s or no as the res ult of s ome c omputation. This is very s imilar to the binary logic that y ou have been s tudy ing. To repres ent
and hold s uc h a res ult, C provides the bool data ty pe. The bool data ty pe allows y ou to hold either true (value 1) or fals e (value 0)
as the res ult. true c an repres ent y es and fals e c an repres ent no. To us e the bool data ty pe, y ou'll need to inc lude the header
< s tdbool.h> Its not over yet !
C provides different data ty pes within the c ategories of the bas ic d...
View Full Document
This document was uploaded on 03/22/2014.
- Fall '14