当前位置:网站首页>【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
因此,我们一定要注意养成一个好的代码输入方式。
边栏推荐
- The final exam first year course
- 7、私信列表
- JetPack component Databinding
- Manchester City confuses fans with smart scarf that detects emotions
- 图像处理技术的心酸史
- Modbus on AT32 MCU
- STM32CUBEMX develops GD32F303 (11) ---- ADC scans multiple channels in DMA mode
- The use of font compression artifact font-spider
- golang GUI for nuxui — HelloWorld
- SQL注入 Less54(限制次数的SQL注入+union注入)
猜你喜欢
图像处理技术的心酸史
221. Largest Square
The use of font compression artifact font-spider
1. Non-type template parameters 2. Specialization of templates 3. Explanation of inheritance
英特尔软硬优化,赋能东软加速智慧医疗时代到来
分布式与集群是什么 ? 区别是什么?
MPPT太阳能充放电控制器数据采集-通过网关采集电池电压容量电量SOC,wifi传输
Word/Excel fixed table size, when filling in the content, the table does not change with the cell content
Static route analysis (the longest mask matching principle + active and standby routes)
The Sad History of Image Processing Technology
随机推荐
The difference between link and @import
Manchester City confuses fans with smart scarf that detects emotions
编译Hudi
The Sad History of Image Processing Technology
Linux下redis7的安装,启动与停止
StringJoiner in detail
mysql view
Observer mode (1)
[1153] The boundary range of between in mysql
Draw Your Cards
[1154] How to convert string to datetime
【银行系列第一期】中国人民银行
Unity3D Button mouse hover enter and mouse hover exit button events
php 网站的多语言设置(IP地址区分国内国外)
Basic learning about Redis related content
tcp框架需要解决的问题
The simulation application of common mode inductance is here, full of dry goods for everyone
Introduction and use of Drools WorkBench
10、Redis实现点赞(Set)和获取总点赞数
11. Redis implements follow, unfollow, and follow and follower lists