c++primer第二章

练习2.1

c++保证short和int至少是16位的,long至少是32位,longlong至少是32位;

有符号类型可以表示正数,负数和零,而无符号类型只能表示不小心于零的数;

float是单精度浮点数,double是双精度浮点数。

练习2.2

使用double或者float

练习2.3

32 4294967264 32 -32 0 0


Exercise 2.10

What are the initial values, if any, of each of the following variables?

std::string global_str;
int global_int;
int main()
{
    int local_int;
    std::string local_str;
}
  • global_str is global variable, so the value is empty string.
  • global_int is global variable, so the value is zero.
  • local_int is a local variable which is not uninitialized, so it has a undefined value.
  • local_str is also a local variable which is not uninitialized, but it has a value that is defined by the class. So it is empty string.

Exercise 2.11

Explain whether each of the following is a declaration or a definition:

  • (a) extern int ix = 1024;
  • (b) int iy;
  • (c) extern int iz;
  • (a): definition.
  • (b): definition.
  • (c): declaration.

练习2.19

说明指针和引用之间的关键区别。

定义

指针是“指向”任何其他类型。

引用是对象的 “另一个名称” 

关键区别

  1. 引用是已存在对象的另一个名称指针就是它自己的对象
  2. 一旦初始化,引用仍然绑定到其初始对象。没有办法重新绑定的引用来引用不同的对象。可以分配复制指针
  3. 引用总是获取引用最初绑定到的对象。一个指针可以在其一生中指向几个不同的对象
  4. 引用必须被初始化。一个指针在定义时不需要初始化
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值