博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小小笔试题(二)
阅读量:6952 次
发布时间:2019-06-27

本文共 1549 字,大约阅读时间需要 5 分钟。

1.9月21日,小米,电子科大笔试题:

void fun()  {      unsigned int a = 2013;      int b = -2;      int c = 0;      while (a + b > 0)      {          a = a + b;          c++;      }      printf("%d", c);  }

  问:输出是什么?

     此题略有陷进。

     a+b相加会自动转换为unsigned int类型,以前一直以为int和unsigned int相加会转换为int!

     因此当a=1时,a+b不是-1,因此死循环,木有输出。

 2.相关知识  

    C++算数运算类型转换 

    Arithmetic conversion proceeds in the following order:

Operand Type Conversion
One operand has  type The other operand is converted to long double.
One operand has double type The other operand is converted to double.
One operand has float type The other operand is converted to float.
One operand has unsigned long long int type The other operand is converted to unsigned long long int
One operand has long long type. The other operand is converted to long long.
One operand has unsigned long int type The other operand is converted to unsigned long int.
One operand has unsigned int type and the other operand has long inttype and the value of the unsigned int can be represented in a long int The operand with unsigned int type is converted to long int.
One operand has unsigned int type and the other operand has long inttype and the value of the unsigned int cannot be represented in a long int Both operands are converted to unsigned long int.
One operand has long int type The other operand is converted to long int.
One operand has unsigned int type The other operand is converted to unsigned int.
Both operands have int type The result is type int.

3. 参考

    

转载于:https://www.cnblogs.com/silver1116/archive/2012/10/09/2717599.html

你可能感兴趣的文章
Linux下comm命令比较两个文件的异同
查看>>
JavaScript继承详解(三)
查看>>
函数的基础及参数
查看>>
Oracle财务系统常用标准报表
查看>>
[CLPR] 定位算法探幽 - 边缘和形态学
查看>>
使用SQL Server Management Studio 创建数据库备份作业
查看>>
DEVOPS基础
查看>>
think in uml 2.1
查看>>
Objective-C Runtime那点事儿
查看>>
JavaIO基础学习笔记
查看>>
18年书单推荐
查看>>
30 个惊艳的 Bootstrap 扩展插件
查看>>
我的博客园开通啦!
查看>>
[LeetCode] Number of Islands
查看>>
绿色版Tomcat的配置
查看>>
MAC 终端基本命令
查看>>
css知识
查看>>
supervisor 管理
查看>>
Oracle DB优化-如何看SQL的执行计划+收集表的统计信息
查看>>
深度学习基础系列(六)| 权重初始化的选择
查看>>