TOP - C言語 - 演算子 - == !=

比較結果により 1 か 0 を返します。
下記の結果の場合に 1 となります。
==   : 左辺値と右辺値が等しい
!=   : 左辺値と右辺値が等しくない

(例)
#include <stdio.h>

int main ()
{
    char *s1 = "aaa";
    char *s2 = "bbb";

    printf("1 == 1  : %d\n", (1 == 1));
    printf("1 == 2  : %d\n", (1 == 2));
    printf("'a' == 'a'  : %d\n", ('a' == 'a'));
    printf("'a' == 'b'  : %d\n", ('a' == 'b'));
    printf("s1(%s) == \"aaa\"  : %d\n", s1, (s1 == "aaa"));
    printf("s2(%s) == \"aaa\"  : %d\n", s2, (s2 == "aaa"));
    printf("\n");

    printf("1 != 1  : %d\n", (1 != 1));
    printf("1 != 2  : %d\n", (1 != 2));
    printf("'a' != 'a'  : %d\n", ('a' != 'a'));
    printf("'a' != 'b'  : %d\n", ('a' != 'b'));
    printf("s1(%s) != \"aaa\"  : %d\n", s1, (s1 != "aaa"));
    printf("s2(%s) != \"aaa\"  : %d\n", s2, (s2 != "aaa"));

    return 0;
}

実行結果
1 == 1  : 1
1 == 2  : 0
'a' == 'a'  : 1
'a' == 'b'  : 0
s1(aaa) == "aaa"  : 1
s2(bbb) == "aaa"  : 0

1 != 1  : 0
1 != 2  : 1
'a' != 'a'  : 0
'a' != 'b'  : 1
s1(aaa) != "aaa"  : 0
s2(bbb) != "aaa"  : 1


Copyright(C) 2006-2012 CLAYPOT. All Rights Reserved.