布尔比较说它为真,但if说它为假
Boolean comparison says it is true but the if says it is false
抱歉,如果这个问题对你们来说太基本了,但是我有这个代码让我困惑。我在if语句之前创建了一个布尔比较,并将相同的比较放到if条件中,但它不会在if块中执行。
#include<iostream> #include<cstdio>
using namespace std;
int main()
{
float s[2] = {0.24};
printf("Is this is true? (1 = yes, 0= false): %d", s[0] >= 0) && (s[0] < (1/7 + 1/14));
printf("nBefore if: s[%d] %fn", 0, s[0]);
if ((s[0] >= 0) && (s[0] < (1/7 + 1/14)))
{
s[0] = 10;
}
printf("nAfter if: s[%d] %fn", 0, s[0]);
return 0;
}
printf("Is this is true? (1 = yes, 0= false): %d", s[0] >= 0) && (s[0] < (1/7 + 1/14));
应 printf("Is this is true? (1 = yes, 0= false): %d", s[0] >= 0 && (s[0] < (1/7 + 1/14)))
;
先做s[0] >= 0
的printf
再做printf
的&&
相关文章:
- 一个关于在C++中重载布尔运算符的问题
- 提升精神:解析布尔表达式并简化为规范范式
- 简化对两个布尔值的 4 个 if/else 检查
- 在C++中做一个场景问题,我不确定如何处理布尔和if循环
- 在 if 语句中返回布尔值的 lambda 表达式
- 在单个if语句中测试多个布尔值
- 布尔变量 if 语句 C++ 上的分段错误
- 布尔表达式是否像使用 if 或 switch 进行分支一样繁琐?
- 布尔逻辑,If 语句约简
- "if (var)"使用数字转换而不是布尔值
- C++ 嵌套'if'语句中的所有代码都会运行,即使这会更改外部语句的布尔值?
- 可能由if语句引起的C++布尔逻辑错误
- 如何启动具有许多布尔参数的函数模板,而不使用 2^n if 语句
- C++Bare布尔表达式(不包含if、while或其他语句)
- 避免使用静态布尔值上的if语句进行逻辑决策
- 使用If语句处理布尔值
- 关于布尔值的If和If /else
- 布尔比较说它为真,但if说它为假
- 布尔和if语句的问题
- 在if语句的条件块中调用布尔方法