C/C++知识点之C++ primer plus Chapter 3
小标 2018-08-27 来源 : 阅读 1885 评论 0

摘要:本文主要向大家介绍了C/C++知识点之C++ primer plus Chapter 3,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

本文主要向大家介绍了C/C++知识点之C++ primer plus Chapter 3,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

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/C+频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved