Home  >  Article  >  Backend Development  >  What are the data types of the operands on both sides of the logical operator?

What are the data types of the operands on both sides of the logical operator?

青灯夜游
青灯夜游Original
2020-07-22 13:16:1418177browse

The data type of the operands on both sides of the logical operator: it can be any legal type of data; because the operands on both sides of the logical operator are eventually converted into bool value (logical value) operations. 0 and null are converted to false, and all non-zero, non-false, and non-null values ​​are converted to true; then the operation is performed.

What are the data types of the operands on both sides of the logical operator?

Logical operators treat their operands as conditional expressions (equations compared to the Boolean value true). The operands are first evaluated, and converted As a logical value (boolean value), 0 and null are converted to false, and all non-zero, non-false, and non-null values ​​are converted to true. If the result is false, the condition is false, and if the result is true, the condition is true.

Because both sides of the logical operator are eventually converted into bool value operations, the bool value only has non-zero (represented by 1) and zero, so as long as it is not zero, it will be converted to 1 , so any value of any type can participate in the operation.

Logical Operators: In formal logic, logical operators or logical connectives connect statements into more complex statements. A new proposition or proposition composed of two propositions is called a compound proposition or compound proposition.

The reason there are two different forms of operators for "and" and "or" is that their precedence is different. Operators are used to perform program code operations on multiple operand items.

Notes:

The rules for using logical operators in C language are as follows:

1. Logical operators return true or false values ​​based on the value of the expression. In C language, there are no special true values ​​and false values, so non-0 can be considered a true value and 0 is a false value.

2. Logical operator operation rules: || or: in two situations, as long as one of them is true, the result is true; && and: in two conditions, if both conditions are true at the same time If it is true, the result is true, otherwise, it is not true, and the opposite meaning is taken. If it is true, the result is false, and if it is false, the result is true.

C language is a general-purpose computer programming language with a wide range of applications. C language is designed to provide a programming language that can be easily compiled, handle low-level memory, and generate small amounts of machine code. and runs without the need for any runtime support.

Although the C language provides many low-level processing functions, it still maintains good cross-platform characteristics. C language programs written with standard specifications can be compiled on many computer platforms, even including some embedded processing processor (MCU or MCU) and supercomputer operating platform.

Related recommendations: "c Language Tutorial"

The above is the detailed content of What are the data types of the operands on both sides of the logical operator?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn