惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
L
LangChain Blog
Y
Y Combinator Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
V
Visual Studio Blog
小众软件
小众软件
月光博客
月光博客
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
美团技术团队
量子位

Victrid's Personal Site

斯普拉遁3打工模式联机网络过程分析 DHCP无类型静态路由──一个摆设 配置透明代理,实现无感上网 Generating Unlimited Grammar: A Messenger Perspective LaTeX插入其他PDF中的矢量图 光速不变原理和迈克尔孙──莫雷实验 交大葡萄演义 调试微信内置浏览器 欧悌甫戎篇 苏格拉底的申辩篇 LCA 最近公共祖先 弥罗斯人的辩论 埃斯库罗斯作品:波斯人、阿伽门农 电路理论资料 Coronavirus: A Humanitarian Crisis 雨夜 linux配置SSR 二叉堆的实现 懒政 Placement New Flipped: A Love Story 我宁可呆在这样的疯人院里 谈新发本地病例 勇敢与智慧 Powerful but Limited Drafted VLC Libva Error Troubleshooting Ring-Fit新上手 政治艺术化与艺术政治化 动态规划——从分割等和子集入手
判断的短路规则
Victrid · 2020-01-16 · via Victrid's Personal Site

所谓的判断short circuiting,是指在条件判断式中,如果前者已经满足了先决条件,就不会执行后置的表达式。例如下面这个程序:

1
2
3
4
5
6
7
int x = 0;
if (false && ++x)
cout << x;
if (true || ++x)
cout << x;
cout << x;
return 0;

屏幕输出为00。这个操作不是编译时处理,而是程序运行时处理的,因此,即便是换成以下程序

1
2
3
4
5
6
7
8
int x;
std::cin >> x;
if (x!=0 && ++x)
std::cout << x;
if (x==0 || ++x)
std::cout << x;
std::cout << x;
return 0;

当输入0时也仍然输出00。判断的实现是基于条件下的跳转,而不是编译器优化。

Author: Victrid

Permanent Link: https://victrid.dev/2020/pan-duan-de-duan-lu-gui-ze/

License: Copyright (c) 2025 victrid Terms of Use

Ads by Google

Read our privacy policy on how these personalized advertisements are delivered to you.

For your reading experience, we provide full-text RSS feeds. Although math formulas cannot be displayed well, the interface can be adjusted as you like and there are no ads.