逻辑 AND 和 OR 运算符
这些运算符在 C++中具有通常的优先级:OR 之前的 AND。
// You can drive with a foreign license for up to 60 days
bool can_drive = has_domestic_license || has_foreign_license && num_days <= 60;
此代码等效于以下内容:
// You can drive with a foreign license for up to 60 days
bool can_drive = has_domestic_license || (has_foreign_license && num_days <= 60);
添加括号不会改变行为,但它确实使它更容易阅读。通过添加这些括号,不存在关于作者意图的混淆。