8. 逻辑操作符
&& 逻辑与
|| 逻辑或
逻辑与和或的特点:
&&左边为假,右边就不计算了
|| 左边为真,右边就不计算了
例:360笔试题
#include <stdio.h>
int main()
{
int i = 0, a = 0, b = 2, c = 3, d = 4;
i = a++ && ++b && d++;
//i = a++ || ++b || d++;
printf("a=%d b=%d c=%d d=%d\n", a, b, c, d);//1,2,3,4
return 0;
}
#include <stdio.h>
int main()
{
int i = 0, a = 0, b = 2, c = 3, d = 4;
//i = a++ && ++b && d++;
i = a++ || ++b || d++;
printf("a=%d b=%d c=%d d=%d\n", a, b, c, d);
return 0;
}
#include <stdio.h>
int main()
{
int i = 0, a = 1, b = 2, c = 3, d = 4;
i = a++ && ++b && d++;
//i = a++ || ++b || d++;
printf("a=%d b=%d c=%d d=%d\n", a, b, c, d);
return 0;
}
#include <stdio.h>
int main()
{
int i = 0, a = 1, b = 2, c = 3, d = 4;
//i = a++ && ++b && d++;
i = a++ || ++b || d++;
printf("a=%d b=%d c=%d d=%d\n", a, b, c, d);
return 0;
}