{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# CHAP10 - Chapter 10 Simple Data Types Built-In and...

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

1 Chapter 10 Simple Data Types: Built-In and User-Defined Dale/Weems/Headington

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

View Full Document
2 Chapter 10 Topics External and Internal Representations of Data Integral and Floating Point Data Types Using Combined Assignment Operators Prefix and Postfix Forms of Increment and Decrement Operators Using Ternary Operator Using Type Cast Operator Using an Enumeration Type Creating and Including User-Written Header Files
3 C++ Simple Data Types C++ Simple Data Types simple types integral floating char short int long bool enum float double long double unsigned

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

View Full Document
4 By definition, the size of a C++ char value is always 1 byte. exactly one byte of memory space Sizes of other data type values in C++ are machine-dependent. ‘A’
5 Using one byte ( = 8 bits ), HOW MANY DIFFERENT NUMBERS CAN BE REPRESENTED USING 0’s and 1’s? Each bit can hold either a 0 or a 1. So there are just two choices for each bit, and there are 8 bits. 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 2 8 = 256 0 1 1 0 0 0 1 1

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

View Full Document
6 Similarly, using two bytes ( = 16 bits), 2 16 = 65,536 DIFFERENT NUMBERS CAN BE REPRESENTED. If we wish to have only one number representing the integer zero, and half of the remaining numbers positive, and half negative, we can obtain the 65,536 numbers in the range below : -32,768 . . . . 0 . . . . 32,767 0 1 0 0 1 0 1 0 0 1 1 0 0 0 1 1
7 Some Integral Types Type Size in Bytes Minimum Value Maximum Value char 1 -128 127 short 2 -32,768 32,767 int 2 -32,768 32,767 long 4 -2,147,483,648 2,147,483,647 NOTE: Values given for one machine. Actual sizes are machine-dependent .

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

View Full Document
8 Data Type bool domain contains only 2 values, true and false allowable operation are the logical ( !, &&, ||) and relational operations
9 Operator sizeof DEFINITION C++ has a unary operator named sizeof that yields the size on your machine, in bytes, of its single operand. The operand can be a variable name, or it can be the name of a data type enclosed in parentheses. int age ; cout << “Size in bytes of variable age is “ << sizeof age << endl ; cout << “Size in bytes of type float is “ << sizeof ( float ) << endl ;

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

View Full Document
10 The only guarantees made by C++ are . . . 1 = sizeof( char ) <= sizeof( short ) <= sizeof( int ) <= sizeof( long ) 1 <= sizeof ( bool ) <= sizeof ( long ) sizeof ( float ) <= sizeof ( double ) <= sizeof ( long double ) char is at least 8 bits short is at least 16 bits long is at least 32 bits
11 Exponential (Scientific) Notation 2.7E4 means 2.7 x 10 4 = 2.7000 = 27000.0 2.7E-4 means 2.7 x 10 - 4 = 0002.7 = 0.00027

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

View Full Document
12 Floating Point Types Type Size in Bytes Minimum Maximum Positive Value Positive Value float 4 3.4E-38 3.4E+38 double 8 1.7E-308 1.7E+308 long double 10 3.4E-4932 1.1E+4932 NOTE: Values given for one machine. Actual sizes are machine-dependent.
13 More about Floating Point Types floating point constants in C++ like 94.6 without a suffix are of type double by default to obtain another floating point type constant a suffix must be used the suffix F or f denotes float type, as in 94.6F the suffix L or l denotes long double, as in 94.6L

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 54

CHAP10 - Chapter 10 Simple Data Types Built-In and...

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

View Full Document
Ask a homework question - tutors are online