逻辑运算符使用分析

1.#include <stdio.h>

int main()
{
    int i = 0;
    int j = 0;
    
    if( ++i > 0 || ++j > 0 )
    {
        printf("%d\n", i);
        printf("%d\n", j);
    }
    
    return 0;
}

2.#include <stdio.h>

int g = 0;

int f()
{
    return g++;
}

int main()
{
    if( f() && f() )
    {
        printf("%d\n", g);
    }
    
    printf("%d\n", g);
    
    return 0;
}
3.#include <stdio.h>

int main()
{
    printf("%d\n", !0);
    printf("%d\n", !1);
    printf("%d\n", !100);
    printf("%d\n", !-1000);
    
    return 0;
}


4.#include <stdio.h>

int main()
{
    int a = 1;
    int b = 2;
    int c = 0;
    
    c = a < b ? a : b;
    
    (a < b ? a : b) = 3;
    
    printf("%d\n", a);
    printf("%d\n", b);
    printf("%d\n", c);
    
    return 0;
}

 

posted @ 2016-12-08 18:05  王小波私人定制  阅读(177)  评论(0编辑  收藏  举报
DON'T FORGET TO HAVE FUN