[Study Notes] [C Language] Relational operators, learning note Operators
1. Condition judgment
By default, every correct code written in the program will be executed. But most of the time, we want to execute a piece of code only when a condition is true.
In this case, you can use conditional statements. However, we do not study conditional statements for the moment. First, let's look at some more basic knowledge: how to judge whether a condition is invalid.
2. true and false
In C language, the condition is true, and the condition is false. Therefore, whether or not the condition is true or false ".
How can we determine whether it is true or false? The C language specifies that all values are false. Any non-0 values are true, and only 0 values are false ". That is to say, 108,-18, 4.5, and-10.5 are all "true", while 0 is "false ".
3. Link comparison
It is often compared during development, such as the card size in the landlords game. You can use Relational operators to compare the sizes of two values.
There are only two types of Relational operators: if the condition is true, the result is 1, that is, "True". If the condition is not true, the result is 0, that is, "false ".
4. Usage notes
=,! In Relational operators ,! = Has the same priority. <, <=,>,> = has the same priority, and the former has a lower priority than the latter: 2 = 3> 1
The Union direction of Relational operators is "from left to right": 4> 3> 2
The priority of Relational operators is less than that of arithmetic operators: 3 + 4> 8-2
1 # include <stdio. h> 2 3 int main () 4 {5/* 6 int a = 10; 7 8 int B = 11; 9 10 // if the condition is true, 1 is returned, true 11 // if the condition is not true, 0 is returned; false 12 int result = B> = a; 13 14 printf ("% d \ n", result ); 15 */16 17 // int a = 2> 3 = 1; 18 // int a = 3 + 4> 8-2; 19 20 int a = 5! = 4 + 2*7> 3 = 10; 21 22 printf ("% d \ n", a); 23 24 return 0; 25}