One, bool Boolean type C language does not have bool type, OC has bool type
is a non-true-and-false data type, with a Boolean type of variable that has only Yes and no two values. Yes indicates that the expression is true and no indicates that the expression is false.
In the C language, it is true that 0 is not.
The bool value is commonly used in branch statements to determine whether an if statement or an else statement is executed.
In a cyclic structure, it is also often used to determine whether a loop is to be executed using the BOOL value.
Precautions:
#define YES 1
#define NO 0
When the computer is recognized, yes is replaced by 1,no instead of 0.
Second, relational operators
> >= <= = = =!
Mainly used for comparison operation, the result of comparison is only true and false two cases, the result value is stored with BOOL type variable.
Note: Determine whether two numbers are equal with = = (double equals).
#import <Foundation/Foundation.h>
int Main (int argc, const Char * argv[])
{
BOOL A = 3 >6;
printf ("a =%d", a);
return 0;
}
BOOL can be seen as a smaller range of shaping, with only two numbers of 1 and 0.
Third, logical operators
An expression consisting of logical operators, and the result is not true or false
&& (Logic and): The result of the entire logical expression is true when the expression on both sides of the operator is true.
|| (logical OR): When the expression on both sides of the operator is false, the result of the entire logical expression is false. An expression | | An expression
! (logical): Reverse the result of an expression.
Short Circuit phenomenon
&& the front is false, the back is not calculated directly to determine the false
Attention to logic and logic or short circuit phenomena
&&------A fake or fake
|| -------is True
Three structures of the program: sequential structure, branching structure, cyclic structure
Iv. If statement
Constructs a branching structure with an if statement, which determines the execution of a branch segment based on the conditions given.
The expression form of the IF statement in C language
1.if (conditional expression) {
Statement 1;
}
When the conditional expression is true, execute statement 1, otherwise skip statement 1 and proceed to the following statement.
eg