当前位置:网站首页>【C语言】表达式求值的一般方法
【C语言】表达式求值的一般方法
2022-07-31 02:45:00 【rookieﻬ°】
表达式求值的方法:
- 表达式求值先看是否存在整形提升或算术转换,再进行计算
- 表达式真正计算的时候先看相邻操作符的优先级决定先算谁
- 相邻操作符的优先级相同的情况下,看操作符的结合性决定计算顺序
当然,不好的输入方式会让程序有多种结果,因此我们应该将计算公式写的没有起义。比如下面这个代码,在不同的编译环境下,结果是不同的:
#include <stdio.h>
int main()
{
int i = 1;
int ret = (++i)+(++i)+(++i);
printf("ret = %d\n", ret);
return 0;
}
不同编译环境可得到以下结果:
- 10
- 12
- 9
因此,我们一定要注意养成一个好的代码输入方式。
边栏推荐
- Draw Your Cards
- Coldfusion file read holes (CVE - 2010-2861)
- 拒绝加班,程序员开发的效率工具集
- Installation, start and stop of redis7 under Linux
- 修改未正确放入沙盒造成苹果兼容性问题
- 1. Non-type template parameters 2. Specialization of templates 3. Explanation of inheritance
- 开题报告之论文框架
- The Sad History of Image Processing Technology
- Drools basic introduction, introductory case, basic syntax
- General introduction to the Unity interface
猜你喜欢
The real CTO is a technical person who understands products
经典链表OJ强训题——快慢双指针高效解法
Static route analysis (the longest mask matching principle + active and standby routes)
Software accumulation -- Screenshot software ScreenToGif
SQL注入 Less46(order by后的注入+rand()布尔盲注)
ShardingJDBC usage summary
19.支持向量机-优化目标和大间距直观理解
软件积累 -- 截图软件ScreenToGif
工程(五)——小目标检测tph-yolov5
Huawei od dice js
随机推荐
CentOS7下mysql5.7.37的卸载【完美方案】
User interaction + formatted output
7、私信列表
Discourse Custom Header Links
General introduction to the Unity interface
f.grid_sample
Coldfusion file read holes (CVE - 2010-2861)
The Sad History of Image Processing Technology
What level of software testing does it take to get a 9K job?
CMOS和TTL的区别?
基于opencv实现人脸检测
Refuse to work overtime, a productivity tool set developed by programmers
共模电感的仿真应用来了,满满的干货送给大家
自动化办公案例:如何自动生成期数据?
The modification is not properly placed in the sandbox, causing Apple compatibility issues
8、统一处理异常(控制器通知@ControllerAdvice全局配置类、@ExceptionHandler统一处理异常)
SQL注入 Less47(报错注入) 和Less49(时间盲注)
AI中的数学思想
19.支持向量机-优化目标和大间距直观理解
mmdetection trains a model related command