当前位置:网站首页>【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
因此,我们一定要注意养成一个好的代码输入方式。
边栏推荐
- String为什么不可变?
- 分布式与集群是什么 ? 区别是什么?
- TCP/IP四层模型
- 字体压缩神器font-spider的使用
- 【C语言基础】解决C语言error: expected ‘;‘, ‘,‘ or ‘)‘ before ‘&‘ token
- f.grid_sample
- To write good test cases, you must first learn test design
- Static routing + PAT + static NAT (explanation + experiment)
- The modification is not properly placed in the sandbox, causing Apple compatibility issues
- YOLOV5学习笔记(二)——环境安装+运行+训练
猜你喜欢
Static routing + PAT + static NAT (explanation + experiment)
JS 函数 this上下文 运行时点语法 圆括号 数组 IIFE 定时器 延时器 self.备份上下文 call apply
STM32CUBEMX develops GD32F303 (11) ---- ADC scans multiple channels in DMA mode
LeetCode 1161 最大层内元素和[BFS 二叉树] HERODING的LeetCode之路
10. Redis implements likes (Set) and obtains the total number of likes
分布式与集群是什么 ? 区别是什么?
6、显示评论和回复
There is a problem with the multiplayer-hlap package and the solution cannot be upgraded
全流程调度——MySQL与Sqoop
Introduction to flask series 】 【 flask - using SQLAlchemy
随机推荐
Calculate S=a+aa+…+aa…a
Unity3D Button mouse hover enter and mouse hover exit button events
Linux下redis7的安装,启动与停止
Refuse to work overtime, a productivity tool set developed by programmers
Real-time image acquisition based on FPGA
你们程序员为什么不靠自己的项目谋生?而必须为其他人打工?
【shell基础】判断目录是否为空
Discourse Custom Header Links
The comprehensive result of the case statement, do you know it?[Verilog Advanced Tutorial]
6. Display comments and replies
The Sad History of Image Processing Technology
[1153] The boundary range of between in mysql
【Android】Room —— SQLite的替代品
The principle of complete replication of virtual machines (cloud computing)
Manchester City confuses fans with smart scarf that detects emotions
8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
CMOS和TTL的区别?
cudaMemcpy study notes
汉源高科8路HDMI综合多业务高清视频光端机8路HDMI视频+8路双向音频+8路485数据+8路E1+32路电话+4路千兆物理隔离网络
Introduction and use of Drools WorkBench