C語言day03-10關(guān)系運(yùn)算符

/**
 *  任何非0的值都為真
 *  只有0才為假
 *
    關(guān)系運(yùn)算符 判斷結(jié)果 只返回 真 與 假
 */
#include <stdio.h>
int main()
{
    /*
     關(guān)系運(yùn)算符:
     
     >
     <
     >=
     <=
     ==
     !=
     
     關(guān)系運(yùn)算符返回值只有兩種,要么真,要么假,1(真)和0(假)
     */
    
    /*
    int a = 10;
    int b = 5;
    int result = a > b; // 嗎? 大于, 真 非0即真.
    printf("result = %i\n",result);
    */
    
    /*
    int a = 10;
    int b = 8;
    int result = a != b;
    printf("result = %i\n",result);
    */
    
    /*
    // 關(guān)系運(yùn)算符注意點(diǎn)
    // 關(guān)系運(yùn)算符也有優(yōu)先級(jí). > < >= <= 優(yōu)先級(jí)大于 == !=
    
    //              1  == 1
//    int result = 1 == 10 > 5 ;
    
    // 算術(shù)運(yùn)算符的優(yōu)先級(jí) 大于 關(guān)系運(yùn)算符
    //              2 < 4
//    int result = 1 + 1 < 2 + 2;
    
    // 關(guān)系運(yùn)算符的結(jié)合型: 從左至右
//    int result = 10 > 3 > 1;
    
    //  如果優(yōu)先級(jí) 和 結(jié)合性 同時(shí)存在, 先優(yōu)先級(jí)再結(jié)合型
    //              11 > 9 == 3 > 1
    //                  1  == 1
    int result = 10 + 1 > 5 + 4 == 3 > 1;
    
    printf("result %i\n",result);
     */
    
    
    // 練習(xí)
//    int result = 3 > 4 + 7;   // 3 > 11 = 0
    
//    int result = (3 + 4) > 7;   // 0 > 7 = 0
    
    //          5 != 4 + 2 * 7 > 3 == 10
    //          5 != 4 + 14 > 3 == 10
    //          5 != 18 > 3 == 10
    //          5 != 1 == 10
    //            1  == 10
    //              0
    int result = 5 != 4 + 2 * 7 > 3 == 10;
    printf(" result = % i\n",result);
   
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容