c++ primer 6第二章数据类型---------读书笔记

数据类型

英文原句:Types are fundamental to any program: They tell us what our data mean and what operations we can perform on those data.

c++ 定义了多种内置类型,并提供了实现自定义类型的机制,
我们熟知的ostream类和istream类就是基于这些机制实现的。

有人问学C++前需要学C吗,我会说,C++本来就没有绕开C.

1 基本内置类型

C++ defines a set of primitive types that include the arithmetic types and a special type named void. The arithmetic types represent characters, integers, boolean values, and floating-point numbers.

c++的基本类型对应于计算机的基本存储单元,和使用这些单元去保存数据的一些常见方式——摘抄于《c++程序设计语言》

1.1算术类型

The arithmetic types are divided into two categories: integral types (which include character and boolean types) and floating-point types.

算术类型的大小跟机器有关,下面是c++标准下的最小尺寸:

在这里插入图片描述
在这里插入图片描述

内容概要:名字、存储大小、表示内容和表示范围、机器实现、有符号/无符号、使用原则、操作

1.2 类型转换

The type of an object defines the data that an object might contain and what operations that object can perform. Among the operations that many types support is the ability to convert objects of the given type to other, related types.

Advice: Avoid Undefined and Implementation-Defined Behavior
避免无法预知和依赖于实现环境的行为

Caution: Don’t Mix Signed and Unsigned Types
不要混合使用有符号和无符号类型

1.3 字面值常量

  • 整型和浮点型
  • 字符和字符串
  • 转义序列(不可打印或有特殊含义的字符)
    在这里插入图片描述
  • 布尔和指针的字面值常量
    true false nullptr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值