Home >Backend Development >C++ >What is the expression of logical truth value in C language?
Logical truth values in C language are represented as 1 (true) and 0 (false) respectively. Logical operators include: &&: logical AND (true when both operands are true) ||: logical OR (true when either operand is true)!: logical NOT (reverse the operands)
Logical truth value representation in C language
In C language, logical truth value is represented by the following integers:
true
): 1false
): 0Logical operators
The C language provides the following logical operators:
&&
: logical AND (if both operands are true , the result is true) ||
: Logical OR (if any operand is true, the result is true) !
: logical NOT (reverses the operands)Example
The following code snippet shows how to use logical operators:
<code class="c">int a = 1; int b = 0; // 检查 a 是否为真且 b 是否为假 if (a && !b) { printf("a 为真且 b 为假\n"); } // 检查 a 是否为真或 b 是否为假 if (a || b) { printf("a 为真或 b 为真\n"); }</code>
In the above example, the condition a && !b
is true because a
is true and b
is false. The condition a || b
is also true because a
is true.
Note
The above is the detailed content of What is the expression of logical truth value in C language?. For more information, please follow other related articles on the PHP Chinese website!