gpt4 book ai didi

c - 当 x 为负时,!x 是否等于真?

转载 作者:行者123 更新时间:2023-12-03 18:39:31 26 4
gpt4 key购买 nike

int main() {

int x = -1;

if (!x) {
printf("Yes\n");

}
}
!x 是负数时 x 是真的还是只有 0 时它是真的?

最佳答案

对于任何非零 x!x 将为零。所以,对于 x == -1!x 是假的。
来自 cppreference :

The logical NOT operator has type int. Its value is ​0​ if expressionevaluates to a value that compares unequal to zero. Its value is 1 ifexpression evaluates to a value that compares equal to zero.

关于c - 当 x 为负时,!x 是否等于真?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65554603/

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