/**
* 任何非0的值都為真
* 只有0才為假
*
關系運算符 判斷結果 只返回 真 與 假
*/
#include <stdio.h>
int main()
{
/*
關系運算符:
>
<
>=
<=
==
!=
關系運算符返回值只有兩種,要么真,要么假,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);
*/
/*
// 關系運算符注意點
// 關系運算符也有優(yōu)先級. > < >= <= 優(yōu)先級大于 == !=
// 1 == 1
// int result = 1 == 10 > 5 ;
// 算術運算符的優(yōu)先級 大于 關系運算符
// 2 < 4
// int result = 1 + 1 < 2 + 2;
// 關系運算符的結合型: 從左至右
// int result = 10 > 3 > 1;
// 如果優(yōu)先級 和 結合性 同時存在, 先優(yōu)先級再結合型
// 11 > 9 == 3 > 1
// 1 == 1
int result = 10 + 1 > 5 + 4 == 3 > 1;
printf("result %i\n",result);
*/
// 練習
// 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;
}
最后編輯于 :
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者