当前位置:网站首页>【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
因此,我们一定要注意养成一个好的代码输入方式。
边栏推荐
- Discourse 自定义头部链接(Custom Header Links)
- StringJoiner详解
- SQL注入 Less47(报错注入) 和Less49(时间盲注)
- YOLOV5学习笔记(二)——环境安装+运行+训练
- 221. Largest Square
- LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING
- golang GUI for nuxui — HelloWorld
- cudaMemcpy study notes
- Brute Force/Adjacency List Breadth First Directed Weighted Graph Undirected Weighted Graph
- Uninstallation of mysql5.7.37 under CentOS7 [perfect solution]
猜你喜欢

Maximum area of solar panel od js

经典链表OJ强训题——快慢双指针高效解法

Observer mode (1)

Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care

Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击

字体压缩神器font-spider的使用

CMOS和TTL的区别?

STM32CUBEMX develops GD32F303 (11) ---- ADC scans multiple channels in DMA mode

Why is String immutable?

AI在医疗影像设备全流程应用
随机推荐
4、敏感词过滤(前缀树)
10. Redis implements likes (Set) and obtains the total number of likes
TCP/IP四层模型
什么是分布式锁?实现分布式锁的三种方式
The Sad History of Image Processing Technology
SQL注入 Less54(限制次数的SQL注入+union注入)
How to design the changing system requirements
MPPT solar charge controller data collection - through the gateway acquisition capacity battery SOC battery voltage, wi-fi
StringJoiner in detail
String为什么不可变?
LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING
软件积累 -- 截图软件ScreenToGif
完整复制虚拟机原理(云计算)
19. Support Vector Machines - Intuitive Understanding of Optimization Objectives and Large Spacing
6. Display comments and replies
The simulation application of common mode inductance is here, full of dry goods for everyone
Huawei od dice js
AI中的数学思想
Discussion on Service Commitment of Class Objects under Multithreading
Mathematical Ideas in AI