当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《C++程序设计》(英文版) Chapter 10 Topics

资源类别:文库,文档格式:PPT,文档页数:64,文件大小:3.23MB,团购合买
Chapter 10 Topics Built-In Simple Types s Integral and Floating Point Data Types s Using Combined Assignment Operators s Prefix and Postfix Forms of Increment and Decrement Operators Additional C++ Operator
点击下载完整版文档(PPT)

Programming in c++ Simple Data Types: Built-in and Use- Defined Dale/eems/Headington

1 Simple Data Types: Built-in and Use-Defined

Programming in C++ Chapter 10 Topics Built-In Simple Types Integral and Floating Point Data Types Using Combined Assignment Operators Prefix and Postfix Forms of Increment and Decrement Operators Additional C++ Operator Character Sets s Using an Enumeration Type Creating and Including User-Written Header Files

2 Chapter 10 Topics ❖ Built-In Simple Types ❖ Integral and Floating Point Data Types ❖ Using Combined Assignment Operators ❖ Prefix and Postfix Forms of Increment and Decrement Operators ❖ Additional C++ Operator ❖ Character Sets ❖ Using an Enumeration Type ❖ Creating and Including User-Written Header Files

Programming in C++ Built-In Simple Types o Simple(atomic)data type A data type in which each value is atomic(indivisible) 心 Example: a single character of type char is atomic, but the string Good Morning is not

3 Built-In Simple Types ❖Simple(atomic)data type: A data type in which each value is atomic(indivisible). ❖Example: a single character of type char is atomic, but the string “Good Morning” is not

Programming in C++ C++ Simple Data Types simple types ntegral floating char short int long bool enum float double long double unsigned

4 C++ Simple Data Types simple types integral floating char short int long bool enum float double long double unsigned

Programming in C++ 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

5 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’

Programming in C++ Example On one machine, it maybe the case that sizeof(char)=1, sizeof(short)=2 sizeof(int)=4; sizeof(long)=8 On other machine, the size might be as follows sizeof(char)=1, sizeof(short)=2 sizeof(int)=2, sizeof(long)=4

6 Example ❖On one machine,it maybe the case that sizeof(char)=1; sizeof(short)=2; sizeof(int)=4; sizeof(long)=8; ❖On other machine, the size might be as follows: sizeof(char)=1; sizeof(short)=2; sizeof(int)=2; sizeof(long)=4;

Programming in C++ 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

7 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

Programming in C++ Using one byte(=8 bits ) 01 000 HOW MANY DIFFERENT NUMBERS CAN BE REPRESENTED USING Os and 1s? Each bit can hold either a 0 or a 1. So there are just two choices for each bit. and there are 8 bits 2x2x2x2x2x2x2x2=28=256

8 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 = 28 = 256 0 1 1 0 0 0 1 1

Programming in C++ Similarly, using two bytes(=16 bits) 0110001 0100 1010 16 65536 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 32767

9 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 1 0 0 0 1 1 0 1 0 0 1 0 1 0

Programming in C++ Range of Values The interval within which values of a numeric type must fall, specified in terms of the largest and smallest allowable values 10

10 Range of Values The interval within which values of a numeric type must fall,specified in terms of the largest and smallest allowable values

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共64页,可试读20页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有