---BOOL
BOOL BOOL a = YES; printf("%d ", a); a = NO; printf("%d", a); int a = 0 , b = 0; BOOL result = YES; result = a > b; printf("%d ", result); result = a == b; printf("%d ",result); result = (a + b) <= ( a - b ); printf("%d ", result); int a = 5 , b = 8, c = 2; BOOL result = a > b && a < c ; printf("result = %d ",result); BOOL result1 = b != c && a >= c ; printf("result1 = %d",result1);
——关系运算符
-> > < == >= <=
->两边要跟表达式
->结果是Bool值的结果(只有真假两种)
->逻辑与&&
->运算符两侧的表达式都为真,结果才为真,有一个为假,即为假,可理解为并且
->逻辑或 ||
->有一个为真,返回BOOL值为真
->逻辑非
——短路现象
->逻辑与和逻辑或当判断第一个条件为假的时候,就不执行第二个条件了,如果第一个为真则再进行第二个语句的判断

1 //逻辑或 2 BOOL result = a == b || b >= c; 3 printf("result = %d ",result); 4 //逻辑非 5 BOOL result1 = !(a > c); 6 printf("result1 = %d", result1 ); 7 // 短路现象 8 int a = 5 , b = 8,c = 2 ; 9 BOOL result = a >= b && ++c; 10 printf("result = %d",c ); 11 int a = 5, b = 8,c = 2,d = 4; 12 BOOL r = (a >= b && b == c)||(a != b || b <= d ); 13 printf("r = %d",r );
—if分支结构
if(条件)
{
语句
}
->如果为真,执行下面语句块
->如果为假,跳出,执行if以外的语句块

char a = 0; scanf("%c",&a); if (a == 'm' || a == 'M') { printf("男"); } else printf("女"); char a = 0 ; scanf("%c",&a); if (a == 77 || a == 109) { printf("男"); } else printf("nv"); printf("hello"); int n = 0; scanf("%d",&n); if (n >=0 && n <=18) { printf("%d在范围之内", n ); } else printf("%d不在范围之内 ", n ); printf("hello");
->判断是否为闰年
//能被400 整除 或者能被4 但不能被100 整除 int a = 0; scanf("%d",&a); if (a % 400 == 0 || (a % 4 == 0 && a % 100 != 0)) { printf("run"); } else printf("NO");
->switch(整型表达式) case 语法
->swich只能是具有整型结构的表达式
->case后面只能跟常量(整型常量或字符常量)
->break的作用用于跳出整个switch case
->case 的值不能够重复
->如果没有对应的case,会执行default
->case中需要定义变量的话需要加{}

1 int telnumber = 0; 2 scanf("%d",&telnumber); 3 printf("分机号为%d ",telnumber); 4 switch (telnumber) { 5 case 1: 6 printf("1"); 7 break; 8 case 2: 9 printf("2"); 10 break; 11 case 3: 12 printf("3"); 13 break; 14 case 4: 15 printf("4"); 16 break; 17 case 5: 18 printf("5"); 19 break; 20 case 6: 21 printf("6"); 22 break; 23 default: 24 printf("没有"); 25 break; 26 } 27 printf(" duang!!!!!分析完毕");
->条件运算符(三目运算符)
->条件表达式 ? 表达式:表达式
如果条件表达式为真,则取冒号前面的结果,如果为假,则取后边的结果
int a = 0, b = 0; scanf("%d%d",&a , &b ); int max = 0; max = (a > b )? a * a : b * b; printf("最大值为%d",max);