gpt4 book ai didi

c - c 中没有 bool 条件的 if 循环

转载 作者:行者123 更新时间:2023-11-30 18:21:11 25 4
gpt4 key购买 nike

这里的 if 语句实际上发生了什么?

#include <stdio.h>
int x;
void main()
{
if (x)
printf("hi");
else
printf("how are u");
}

最佳答案

如果 x 非零,则运行

printf("hi");,并且 printf("how are u");如果 x 为零则运行。

条件检查在 C 中正式使用 int 类型(任何其他类型在计算之前隐式转换为 int);不是 bool 类型。

请注意,在您的情况下,x 会自动初始化为 0,因为它处于全局范围。

关于c - c 中没有 bool 条件的 if 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54420584/

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