C++ Primer Plus (Six Edition) Chapter 3, Review
来源:互联网 发布:ddos攻击网络抓包 编辑:程序博客网 时间:2024/06/17 06:39
Q1. Why does C++ have more than one integer type?
A: In order to give users the option of choosing the integer type that best meets a program's particular requirements and save system memory also for which
may speed up the calculation.
Q2. Declare variables matching the following descriptions:
a. A short integer with the value 80
b. An unsigned int integer with the value 42,110
c. An integer with the value 3,000,000,000
A: a. short int a = 80;
b. unsigned int b = 42110;
c. long long c = 3,000,000,000;
Note: Usually you should not make int be large enough to hold 3,000,000,000.
Q3. What safeguards does C++ provide to keep you from exceeding the limits of an integer type?
A: Sateguards are not provided, still we can use the climits header file to determine what the limits are.
Q4. What is the distinction between 31L and 33?
A: The constant 33L is type long, while 33 is type int.
Q5. Consider the two C++ statements that follow:
char grade = 65;
char grade = 'A';
Are they equivalent?
A: No, they only have the same effect on some systems, and ' A ' is a type char, whereas 65 is a type int.
Q6. How could you use C++ to find out which character the code 88 represents? Come up with at least two ways.
A: Here are for ways:
char c = 88;
cout << c << endl;
cout.put(char(88));
cout << char(88) << endl;
cout << (char)88 << endl;
Q7. Assigning a long value to a float can result in a rounding error. What about assigning long to double? long long to double?
A: It depends on how large the two types are. If long is 4 bytes, there's no loss, for the largest long value would be about 2 billion, which is 10 digits.
And because double provides at least 13 significant figures, no rounding would be needed. The long long type, on the other hand, can reach 19
digits, which exceeds the 13 significant figures guaranteed for double. Also note that long long is an integer type, while double is not.
Q8. Evaluate the following expressions as C++ would:
a. 8 * 9 + 2
b. 6 * 3 / 4
c. 3 / 4 * 6
d. 6.0 * 3 / 4
e. 15 % 4
A: They successively yield 74, 4, 0, 4.5, 3.
Q9. Suppose x1 and x2 are two type double variables that you want to add as integers and assign to an integer variable. Construct a C++ statement for doing so. What if
you want to add them as type double and then convert to int?
A: 1. int pos = (int) x1 + (int) x2; // or int pos = int (x1) + int (x2);
2. int pos = (int) (x1 + x2); // or int pos = int (x1 + x2);
Q10. What is the variable type for each of the following declarations?
a. auto cars = 15;
b. auto iou = 150.37f;
c. auto level = ' B ';
d. auto crat = U ' /U00002155 ' ;
e. auto fract = 8.25f / 2.5;
A: They successively are type int, float, char, char32_t and double.
- C++ Primer Plus (Six Edition) Chapter 3, Review
- C++ Primer Plus (Six Edition) Chapter 2, Review
- C++ Primer Plus (Six Edition) Chapter 4, Review
- C++ Primer Plus (Six Edition) Chapter 4, Review
- C++ Primer Plus (Six Edition) Chapter 3, Programming Exercises
- C++ Primer Plus (Six Edition) Chapter 2, Programming Exercises
- C++ primer plus Six Edition //2.7.3 答案程序
- C Primer Plus. Fifth Edition 翻译Chapter 3 数据和C (Data and C)第一部分
- C Primer Plus. Fifth Edition 翻译Chapter 3 数据和C (Data and C)之二
- C primer plus -- Chapter 2
- c primer plus 4th edition Programing Exercises answer(chapter 6)
- c primer plus 4th edition Programing Exercises answer(Chapter 7)
- C Primer Plus Fifth Edition 笔记chapter1
- C Primer Plus Fifth Edition 笔记chapter2
- C Primer Plus (5th Edition)
- c primer plus Chapter 14 p383
- 《C primer plus》笔记--Chapter 1
- c++ primer plus笔记 [chapter 3]
- 【JavaWeb-4】Tomcat以及手动、自动部署项目
- 150辆大巴车免费乘,但盈利却上亿,为何? 商业模式你知道吗
- 喷水装置(二)题目及解法
- OBJ文件解析之静态链接的效果
- curl命令详解
- C++ Primer Plus (Six Edition) Chapter 3, Review
- java中按值传递还是按引用传递--string
- 【BZOJ4542】大数, 莫队
- 封装了一个TPlayGif插件
- Android Spinner选择同一个选项时触发onItemSelected事件
- WHERE 子句运算符
- Android Studio使用系列——butterknife插件代替findViewById
- 【网络编程】南工聊天服务器源码
- 模糊查询