当前位置:网站首页>【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
因此,我们一定要注意养成一个好的代码输入方式。
边栏推荐
- AI中的数学思想
- 图解lower_bound&upper_bound
- 16. Registration Center-consul
- The use of font compression artifact font-spider
- Real-time image acquisition based on FPGA
- The comprehensive result of the case statement, do you know it?[Verilog Advanced Tutorial]
- 19.支持向量机-优化目标和大间距直观理解
- The whole process scheduling, MySQL and Sqoop
- Installation, start and stop of redis7 under Linux
- Coldfusion file read holes (CVE - 2010-2861)
猜你喜欢

To write good test cases, you must first learn test design

Linux下redis7的安装,启动与停止

图像处理技术的心酸史

Intranet Infiltration - Privilege Escalation

How to do a startup CTO?

YOLOV5学习笔记(三)——网络模块详解

f.grid_sample

SQL注入 Less54(限制次数的SQL注入+union注入)

Discourse 自定义头部链接(Custom Header Links)

The use of font compression artifact font-spider
随机推荐
The whole process scheduling, MySQL and Sqoop
YOLOV5学习笔记(二)——环境安装+运行+训练
Draw Your Cards
Drools basic introduction, introductory case, basic syntax
try-catch中含return
Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
The simulation application of common mode inductance is here, full of dry goods for everyone
STM32CUBEMX开发GD32F303(11)----ADC在DMA模式下扫描多个通道
Modbus on AT32 MCU
自动化办公案例:如何自动生成期数据?
共模电感的仿真应用来了,满满的干货送给大家
10、Redis实现点赞(Set)和获取总点赞数
How to design the changing system requirements
YOLOV5 study notes (2) - environment installation + operation + training
[1154] How to convert string to datetime
软件积累 -- 截图软件ScreenToGif
11、Redis实现关注、取消关注以及关注和粉丝列表
Static routing + PAT + static NAT (explanation + experiment)
execsnoop 工具
Linux下redis7的安装,启动与停止