---BOOL
BOOL
BOOL a = YES;
printf("%d\n", a);
a = NO;
printf("%d", a); int a = , b = ;
BOOL result = YES;
result = a > b;
printf("%d\n", result);
result = a == b;
printf("%d\n",result); result = (a + b) <= ( a - b );
printf("%d\n", result);
int a = , b = , c = ;
BOOL result = a > b && a < c ;
printf("result = %d\n",result);
BOOL result1 = b != c && a >= c ;
printf("result1 = %d",result1);
——关系运算符
-> > < == >= <=
->两边要跟表达式
->结果是Bool值的结果(只有真假两种)
->逻辑与&&
->运算符两侧的表达式都为真,结果才为真,有一个为假,即为假,可理解为并且
->逻辑或 ||
->有一个为真,返回BOOL值为真
->逻辑非
——短路现象
->逻辑与和逻辑或当判断第一个条件为假的时候,就不执行第二个条件了,如果第一个为真则再进行第二个语句的判断
//逻辑或
BOOL result = a == b || b >= c;
printf("result = %d\n",result);
//逻辑非
BOOL result1 = !(a > c);
printf("result1 = %d", result1 );
// 短路现象
int a = , b = ,c = ;
BOOL result = a >= b && ++c;
printf("result = %d",c );
int a = , b = ,c = ,d = ;
BOOL r = (a >= b && b == c)||(a != b || b <= d );
printf("r = %d",r );
—if分支结构
if(条件)
{
语句
}
->如果为真,执行下面语句块
->如果为假,跳出,执行if以外的语句块
char a = ;
scanf("%c",&a);
if (a == 'm' || a == 'M') {
printf("男");
}
else
printf("女"); char a = ;
scanf("%c",&a);
if (a == || a == ) {
printf("男");
}
else
printf("nv");
printf("hello"); int n = ;
scanf("%d",&n);
if (n >= && n <=) {
printf("%d在范围之内", n );
}
else
printf("%d不在范围之内\n", n );
printf("hello");
->判断是否为闰年
//能被400 整除 或者能被4 但不能被100 整除 int a = ; scanf("%d",&a); if (a % == || (a % == && a % != )) { printf("run"); } else printf("NO");
->switch(整型表达式) case 语法
->swich只能是具有整型结构的表达式
->case后面只能跟常量(整型常量或字符常量)
->break的作用用于跳出整个switch case
->case 的值不能够重复
->如果没有对应的case,会执行default
->case中需要定义变量的话需要加{}
int telnumber = ;
scanf("%d",&telnumber);
printf("分机号为%d\n",telnumber);
switch (telnumber) {
case :
printf("");
break;
case :
printf("");
break;
case :
printf("");
break;
case :
printf("");
break;
case :
printf("");
break;
case :
printf("");
break;
default:
printf("没有");
break;
}
printf("\nduang!!!!!分析完毕");
View swich
->条件运算符(三目运算符)
->条件表达式 ? 表达式:表达式
如果条件表达式为真,则取冒号前面的结果,如果为假,则取后边的结果
int a = , b = ;
scanf("%d%d",&a , &b );
int max = ;
max = (a > b )? a * a : b * b;
printf("最大值为%d",max);