将输入与两个字符进行比较,会产生奇怪的警告

标签 c logic

我试图将输入与两个不同的字符进行比较,并在满足其中一个条件时执行 if 条件。

到目前为止我的代码是:

if(i == 'Y'||'y') {
        //code here
}

但是 GCC 编译器会发出警告:

warning: use of logical '||' with constant operand
      [-Wconstant-logical-operand]

为什么会发生这种情况?

最佳答案

你想说的是:

  if(i == 'Y'|| i == 'y')

编译器正在准确地告诉您您需要了解的内容!

关于将输入与两个字符进行比较,会产生奇怪的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39419668/

相关文章:

iphone - 困惑的方法 - if/then 结构和字符串操作问题

c# - 从 C# 调用 C DLL 方法的正确方法

logic - Z3 SMT 求解器中的常数相等

javascript - (this) 在这段代码中如何工作,javascript?

c - Unix 域套接字 : Using datagram communication between one server process and several client processes

macos - OSX 音频 : use Garage Band Plug-ins in my own app

javascript - javascript中的数组问题: Logic

c - 如何在 Visual Studio 中修复 "return value ignored: ' scanf'"代码 C6031

c - 警告 : declaration of '...' will not be visible outside this function [-Wvisibility]

c - 当我尝试在队列中添加元素时出现段错误