【C言語】
論理演算子||に定数を使った!
if(x == ‘a’ || ‘A’){

誤り: if(x == 'a'||'A') 正解: if(x=='a'||x=='A')

warning: use of logical ‘||’ with constant operand

警告:論理演算子||に定数を使った
[-Wconstant-logical-operand]


■’b’を入力すると何と表示されますか?

#include <stdio.h>
int main(void){
    int x = getchar();//'b'を入力してね
    if(x == 'a' || 'A'){
        printf("A=%c",x);
    } else 
    if(x == 'b' || 'B'){
        printf("B=%c",x);
    } else {
        printf("C=%c",x);    
    }
}

解答は自分でコンパイル&実行してね。


■if(x == 1 || 2)

int f(int x) {
    if(x == 1 || 2)
        return  1;
    return  0;
}

論理演算子に定数を使用するのは間違いの可能性が高いです。

if(x == 1 || 2){ //原作は次のどちらかの誤り

if(x == 1 || x==2){ 

if(x == (1 |2)){ 

■case 1||2:

(warning): Found suspicious case label in switch(). Operator ‘||’ probably doesn’t work as intended.

警告:怪しいcaseラベル。論理演算子は期待した動きをしない。[(warning)suspiciousCase]

int f(int x) {
    switch(x){
    case    0:
    case    1||2://ダメ
    case    4:
        return  1;
    }
    return  0;
}

case 1||2は(論理演算子)
case 1|2か(ビット演算子)
case 1:
case 2:の誤りと思われます。