16simpTypes_3014

# 16simpTypes_3014 - Lecture File 16 COP 3014 January 16,...

This preview shows pages 1–5. Sign up to view the full content.

Lecture File 16 COP 3014 January 16, 2008 A. Ford Tyson 1 ± Simple Data Types integra COP 3014 Lecture File 16 1 –integral –floating point –enumeration Copyright 1997-present, Ann Ford Tyson Data Types ± Data Type – a set of possible values (e.g. the set of integers) plus a set of legal operations on those values (e.g. addition, subtraction, 2 etc.) ± Simple Data Type – set of distinct "atomic" values (no component parts) and operations – e.g. 'A' 17 -3.14 Simple Data Types in C++ integral floating 3 int char short long [ unsigned ] bool enum float double long double

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Lecture File 16 COP 3014 January 16, 2008 A. Ford Tyson 2 integral types ± have discrete values which are ordered -5 < 17 'A' < 'C' false < true 4 ± each value has a unique successor and predecessor in the data type (unless it is at the end of the range) what comes after 5? 6 (no question!) floating point types ± have values which are ordered but are not discrete ± a value does not have a unique successor or a predecessor in the data 5 type what comes after 5.0? depends on precision of machine 5.00001 5.000001 5.0000001 ??? using integer vs float: loops and switch ± we use integral types only for loop control variables and for switch control ± for (x = 5 0; x < 6 0; x++) NOT used 6 for (x 5.0; x < 6.0; x++) NOT used ± for (i = 5; i < 6; i++) IS used ± switch (<case selector>) { case <label1> : . .. integral only !
Lecture File 16 COP 3014 January 16, 2008 A. Ford Tyson 3 More about integral types ± type ranges are in climits ± range is determined by precision ± in INT MIN thru INT MAX 7 int INT_MIN thru INT_MAX short int SHRT_MIN thru SHRT_MAX long int LONG_MIN thru LONG_MAX and 0 thru UINT_MAX, USHRT_MAX, or ULONG_MAX char CHAR_MIN thru CHAR_MAX unsigned char 0 thru UCHAR_MAX More about integral types p.2 ± ANSI standard guarantees that 1 <= sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long) 8 ± on our platform: 1 2 4 4 (bytes) ± examples: literal integral constants 5 defaults to int 5L forces it to a long int 05 makes it octal (base 8) More about floating types ± type ranges and max number of digits in mantissa are in cfloat ± range is determined by precision 9 ± float FLT_MIN thru FLT_MAX double DBL_MIN thru DLB_MAX long double LDBL_MIN thru LDBL_MAX

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Lecture File 16 COP 3014 January 16, 2008 A. Ford Tyson 4 More about floating types p.2 ± ANSI standard guarantees that sizeof (float) <= sizeof (double) <= sizeof (long double) note: double comes from double precision 10 ± on our platform: 4 8 8 (bytes) FLT_DIG is 6, DBL_DIG is 15 ± examples: literal floating constants 5.0
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/14/2011 for the course COP 3014 taught by Professor Tyson during the Fall '10 term at FSU.

### Page1 / 13

16simpTypes_3014 - Lecture File 16 COP 3014 January 16,...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online