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

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

View Full Document Right Arrow Icon
1 Chapter 10 Simple Data Types: Built-In and User-Defined Dale/Weems/Headington
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
3 C++ Simple Data Types C++ Simple Data Types simple types integral floating char short int long bool enum float double long double unsigned
Background image of page 3

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

View Full DocumentRight Arrow Icon
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’
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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 .
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Data Type bool domain contains only 2 values, true and false allowable operation are the logical ( !, &&, ||) and relational operations
Background image of page 8
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 ;
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
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
Background image of page 11

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

View Full DocumentRight Arrow Icon
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.
Background image of page 12
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
Background image of page 13

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

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/13/2011 for the course CSC 140 taught by Professor Lebre during the Spring '04 term at Moraine Valley Community College.

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 Right Arrow Icon
Ask a homework question - tutors are online