一、關系運算符
/*
關系運算符:
>
<
>=
<=
==
!=
關系運算符的返回值只有兩種,要么真,要么假,1(真)和0(假)
int result = a > b; // 嗎? 大于, 真,非0即真.
*/
// 關系運算符注意點
// 關系運算符也有優先級, > < >= <= 優先級大于 == != 【int result = 1 == 10 > 5 ;】
// 算術運算符的優先級 大于 關系運算符 【int result = 1 + 1 < 2 + 2;】
// 關系運算符的結合性 : 從左至右 【int result = 10 > 3 > 1;】
// 如果優先級和結合性同時存在, 先優先級 再 結合性 【int result = 10 + 1 > 5 + 4 == 3 > 1;】 // 【int result = ((10 + 1) > (5 + 4)) == (3 > 1);】
二、代碼
#include <stdio.h>
int main()
{
/*
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);
*/
/*
// 1 == 1
// int result = 10 > 5 == 1;
// int result = 1 == 10 > 5 ;
// 2 < 4
// int result = 1 + 1 < 2 + 2;
// 1 > 1
// int result = 10 > 3 > 1;
// 11 > 9 == 3 > 1
// 1 == 3 > 1
// 1 == 1
// int result = 10 + 1 > 5 + 4 == 3 > 1;
int result = ((10 + 1) > (5 + 4)) == (3 > 1);
printf("result = %i\n",result);
*/
#pragma mark 練習
int result;
result = 3 > 4 + 7; // 3 > 11 = 0
result = (3 > 4) > 7; // 0 > 7 = 0
// 5 != 18 > 3 == 10
// 5 != 1 == 10
// 1 == 10
result = 5 != 4 + 2 * 7 > 3 == 10;
printf("result = %i\n",result);
return 0;
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。