gpt4 book ai didi

c - 关系运算符评估结果

转载 作者:太空狗 更新时间:2023-10-29 14:53:15 24 4
gpt4 key购买 nike

假设我们有一个像

这样的表达式
(x > 5) 

C 语言。语言/标准是否保证表达式在为假时将被评估为 0 ,在为真时被评估为 1

最佳答案

是的,这是由标准保证的。

根据 C11标准文档,第 6.5.8 章,第 6 段,[关系运算符]

Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false. The result has type int.

更新:C99 的同一章节和段落标准也。

关于c - 关系运算符评估结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28538607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com