C++ 比奇数大

标签 c++ if-statement

<分区>

我有一个奇怪的问题。

iGhostLen 为-1,iMaxGhost 为 480。 但仍然是行 iGhostLen=iMaxGhost;被击中。

-1 是特例还是我哪里出错了。 我不认为 -1 大于 480。

谢谢。

unsigned int iMaxGhost=(120 * 4);
int iGhostLen=-1

if (iGhostLen > iMaxGhost)
{
    iGhostLen=iMaxGhost;
}

最佳答案

由于比较有符号和无符号整数,您应该收到编译器警告。将 unsigned int 更改为 int,并阅读一些有关数字表示的内容。

关于C++ 比奇数大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19349480/

相关文章:

python - 这个 Python 程序中的 `else:` 是否正确/必要?

C++ 错误 'else' 没有前一个 'if'

java - 线程中出现异常,java代码将无法正常执行。 if/else 语句

c++ - 试图让我的程序继续使用 if/else 语句 C++

c++ - WaitForInputIdle 不适用于以编程方式启动 mspaint

c++ - 在cpp中使用unix系统调用

c++ - 对不同类型使用shared_ptr

c++ - 我必须初始化简单的类成员变量吗?

c# - C++ inside of C# 通信性能

python - 求助if语句