&& A&&B 同真为真 A\B任意一个为假 即为假 短路特性:如果A=假 则B表达式则不会运行
#include <stdio.h>
#include <stdlib.h>
void test()
{
int n = 10;
printf("n的值为%d\n", n);
(3 < 2) && (n = 100);
printf("n的值为%d\n", n);
}
int main(int argc, char *argv[])
{
test();
system("pause");
return 0;
}
输出结果
n的值为10
n的值为10
|| A||B 同假为真 A\B任意一个为真 即为真 短路特性:如果A=真 则B表达式则不会运行
#include <stdio.h>
#include <stdlib.h>
void test()
{
int n = 10;
printf("n的值为%d\n", n);
(3 > 2) || (n = 100);
printf("n的值为%d\n", n);
}
int main(int argc, char *argv[])
{
test();
system("pause");
return 0;
}
n的值为10
n的值为10