As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center作为指导。
                            
                        
                    
                
                                6年前关闭。
            
                    
我想将值与范围的两端进行比较。这是我的代码的样子:

if ( timeramount >5 && <10 )...do some stuff...


因此我的应用程序需要知道timeramount是否大于5但小于10。

有人可以帮忙吗?

最佳答案

逻辑运算符,例如&&||等采用两个操作数。这些操作数必须是表达式。 < 10不是有效的表达式,因为它缺少一个操作数(“小于10的数字是多少?”)。

要用C语言表达您描述为“如果timerarount大于5但小于10”的自然语言,则必须更加冗长:

if (timeramount > 5 && timeramount < 10) {
    /* if timeramount is greater than 5 AND timeramount is less than 10 */
    ;
}


我建议您阅读一本有关C的入门书籍,以学习该语言的基础知识。 Kernighan&Ritchie的“ The C Programming Language”是一个好的开始,但是您可以参考this question

07-24 09:46
查看更多