Logical Operators

C language self-learning logical operators

1 #include <stdlib.h>
 2  
3  int main()
 4  {
 5      int height= 177 ;
 6      double money= 1500000 ;
 7      printf( " Whether it meets the conditions: %d\n " ,height >= 180 && money >= 1000000 ); // And operation, the output result is 0; 
8      printf( " Whether it meets the conditions: %d\n " ,height <= 180 && money >= 1000000 ); // The output result is 1; 
9      printf( " When Eligible when one condition is met:%d\n" ,height>= 180 || money >= 1000000 ); // Or operation, the output result is 1; 
10      printf( " It is qualified when a condition is met: %d\n " ,height >= 180 || money <= 1000000 ); // The output result is 0; 
11      printf( " Whether it meets the conditions: %d\n " ,!(height >= 180 )); // Negative operation, the result is 1; 
12      printf( " Whether it meets the requirements Condition: %d\n " ,!money >= 1000000 ); // The output result is 0; 
13      return  0 ;
 14 }

Then the previous formula is written as a formula that the computer can understand: x>7 && x<100;

The value of logical operation also has two kinds of "true" and "false", which are represented by integer 1 and 0 in C language. Its evaluation rules are as follows:

1) AND operation (&&)

The result is true when both variables involved in the operation are true, otherwise it is false. For example: 5>=5 && 7>5, the result of the operation is true;

2) OR operation (||)

As long as one of the two variables involved in the operation is true, the result is true. When both quantities are false, the result is false. For example: 5>=5||5>8, the operation result is true;

3) NOT operation (!)

When the variable involved in the operation is true, the result is false; when the variable involved in the operation is false, the result is true. For example: !(5>8), the result of the operation is true.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325102577&siteId=291194637