Yas*_*shi 0 c conditional if-statement
有人可以解释我在没有卷曲大括号的情况下编写的嵌套If-Else语句的工作原理.
我想了解为什么以下程序没有给我任何输出.
我检查了所有4种可能性.
(Outer-If,Inner-If)::( True,True),(True,False),(False,True),(False,False).
我在CodeBlocks上编辑,在Windows上使用gcc编译器.
int main()
{
int n=0,m=0;
if ( n > 0 )
if ( m > 0 )
printf("Inner-If Condition satisfied.");
else
printf("Inner-If condition not satisfied. ");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
它们的工作原理是 - 如果在下面的语句中有一个大括号.在你的情况下,然后:
if ( n = 0 ){ // ToDo - did you mean `==`, `n = 0` is `0`.
if ( m = 0 ){ // ToDo - ditto.
printf("True");
} else {
printf("False");
}
}
Run Code Online (Sandbox Code Playgroud)
在你的情况下,我认为困惑源于你的使用=而不是==.