中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
《c++ primer 4th》读书笔记之变量和基本类型
作者:未知 时间:2005-07-27 23:27 出处:CSDN 责编:chinaitpower
              摘要:《c++ primer 4th》读书笔记之变量和基本类型

第一部分 基础
第二章  变量和基本类型
2.1节     系统内置类型
包括 integers, floating-point numbers, and individual characters and boolean values,还有void。
The arithmetic types that represent integers, characters, and boolean values are collectively referred to as the integral types.
整型包括整数、字符、布尔值.
Signed and Unsigned Types
有符号和无符号类型
默认int, short, and long都是有符号类型。字符包括简单、有符号、无符号字符,但是只有两种表示方式,有符号和无符号字符。
浮点类型
浮点类型包括float, double, and long double ,需要注意的是float不是太精确,只有6位有效数字,而double有10位有效数字,
这对于一般的计算已经足够了。
2.2节    文字常量
为什么叫文字常量?
literal because we can speak of it only in terms of its value; constant because its value cannot be changed.
称之为文字是因为我们只能以它的值的形式指代它;称之为常量是因为它的值不能被改变。
每个文字都有相应的类型例如0 是int 型而3.14159 是double 型的。Literals exist only for the built-in types.
There are no literals of class types. Hence, there are no literals of any of the library types
文字仅仅对于内置类型而言,没有类类型的文字,因此,也没有任何库类型的文字。
建议:
In practice, many uses of integers involve counting. For example, programs often count the number of elements in a data structure such as a vector or an array. We'll see in Chapters 3 and 4 that the library defines a set of types to use when dealing with the size of an object. When counting such elements it is always right to use the library-defined type intended for this purpose.

When counting in other circumstances, it is usually right to use an unsigned value. Doing so avoids the possibility that a value that is too large to fit results in a (seemingly) negative result.
When performing integer arithmetic, it is rarely right to use shorts. In most programs, using shorts leads to mysterious bugs when a value is assigned to a short that is bigger than the largest number it can hold. What happens depends on the machine, but typically the value "wraps around" so that a number too large to fit turns into a large negative number. For the same reason, even though char is an integral type, the char type should be used to hold characters and not for computation. The fact that char is signed on some implementations and unsigned on others makes it problematic to use it as a computational type.
On most machines, integer calculations can safely use int. Technically speaking, an int can be as small as 16 bitstoo small for most purposes. In practice, almost all general-purpose machines use 32-bits for ints, which is often the same size used for long. The difficulty in deciding whether to use int or long occurs on machines that have 32-bit ints and 64-bit longs. On such machines, the run-time cost of doing arithmetic with longs can be considerably greater than doing the same calculation using a 32-bit int. Deciding whether to use int or long requires detailed understanding of the  program and the actual run-time performance cost of using long versus int.
Determining which floating-point type to use is easier: It is almost always right to use double. The loss of precision implicit in float is significant, whereas the cost of double precision calculations versus single precision is negligible. In fact, on some machines, double precision is faster than single.The precision offered by long double usually is unnecessary and often entails considerable extra run-time cost


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有