c++ - 对于所有编译器,C++ 中的 If 语句中的各种条件是否总是有相同的执行顺序?
问题描述
让我们假设一个带有两个条件 A 和 B 的简单 If 语句:
If ( condA && condB)
所有编译器的序列都相同吗?
- 条件A
- 条件 B
如果条件 A 已经为假,那么条件 B 的执行是否是可选的?
解决方案
Yes. Not evaluating condition B if A is false is called short circuit logic, and this behavior is guaranteed by the language specification.
推荐阅读
- powerbi - 获取度量以仅在矩阵 Power BI 中显示正值
- python - 熊猫将数据框中的列附加到python中的列表
- bitbucket - Bitbucket API 从分叉回购中提高 PR?
- ibm-cloud - 服务代理记录的 URL 以“没有这样的主机”响应
- javascript - JavaScript 列表按钮。需要列表结束
- javascript - 如何在 vanilla JS 中加密字符串?
- php - 如何在php中对具有第一个数组顺序和第二个数组的2个关联数组进行排序
- c# - 如何使用 Xamarin(Android) 将 VCard 添加到联系人?
- java - 手动 Spring 启动 SQL 脚本
- javascript - 如何在xml中获取孩子?