当前位置:网站首页>【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
因此,我们一定要注意养成一个好的代码输入方式。
边栏推荐
- cudaMemcpy study notes
- Draw Your Cards
- Modbus on AT32 MCU
- Draw Your Cards
- The principle of complete replication of virtual machines (cloud computing)
- Coldfusion file read holes (CVE - 2010-2861)
- Mathematical Ideas in AI
- The Sad History of Image Processing Technology
- LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING
- Drools Rule Properties, Advanced Syntax
猜你喜欢

php 网站的多语言设置(IP地址区分国内国外)

Multilingual settings of php website (IP address distinguishes domestic and foreign)

General introduction to the Unity interface

CorelDRAW2022精简亚太新增功能详细介绍

4. Sensitive word filtering (prefix tree)

Problems that need to be solved by the tcp framework

基于opencv实现人脸检测

英特尔软硬优化,赋能东软加速智慧医疗时代到来

Hanyuan Hi-Tech 8-channel HDMI integrated multi-service high-definition video optical transceiver 8-channel HDMI video + 8-channel two-way audio + 8-channel 485 data + 8-channel E1 + 32-channel teleph

mysql view
随机推荐
There is a problem with the multiplayer-hlap package and the solution cannot be upgraded
数学解决——环形链表问题
Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
What level of software testing does it take to get a 9K job?
try-catch中含return
How to do a startup CTO?
User interaction + formatted output
Multilingual settings of php website (IP address distinguishes domestic and foreign)
LeetCode Daily Question 2022/7/25-2022/7/31
汉源高科8路HDMI综合多业务高清视频光端机8路HDMI视频+8路双向音频+8路485数据+8路E1+32路电话+4路千兆物理隔离网络
How to design the changing system requirements
11、Redis实现关注、取消关注以及关注和粉丝列表
11. Redis implements follow, unfollow, and follow and follower lists
关于 mysql8.0数据库中主键位id,使用replace插入id为0时,实际id插入后自增导致数据重复插入 的解决方法
AI software development process in medical imaging field
Draw Your Cards
Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击
Coldfusion file read holes (CVE - 2010-2861)
CentOS7下mysql5.7.37的卸载【完美方案】
The effective square of the test (one question of the day 7/29)