The Difference between Condition and and Conditional OR in C Language
- 2021-07-22 11:10:18
- OfStack
I will not introduce it in detail, but analyze it with the case as follows:
The conditional OR operator () performs the logical OR of the bool operand, but evaluates the second operand only if necessary.
The "and" operator ( & & ) Performs a logical AND operation on its bool operand, but evaluates the second operand only if necessary
At the same time, we also need to understand that and & & Are left associative logical operators, so look at the following example
class Program
{
static void Main(string[] args)
{
int a = 9;
int b = 10;
int c = 11;
int d = 12;
if (d>b || c > b && a>b)
{
Console.WriteLine("true");
}
Console.ReadKey();
}
}
So after judging d > When b is true, the latter part of c > b & & a > b will not be operated again and will enter the conditional statement
Through the above, I hope I can help to get home.