Home > database >  College students' C second chapter notes
College students' C second chapter notes

Time:10-18

16.2.4.2 comma operators, relationship between operations, logic operations, conditions for operation
Comma is operator, it connects two expressions, expression to compute the left, then calculate the expression, after the two expressions are calculated, in the expression on the right, for the final result,
Relational operators are used to compare the size of the two expressions are equal and unequal relationship
Logical operators is not logically and logic or logic operation
Conditional expression can be the choice of simple structure,
Comma operation and comma expression
Format:
The expression 1, 2
To solve the order and the results
To solve the expression 1 first, to solve the expression 2
The final result with the value of expression 2
For example: a=3 * 5, a * 4 final results of 60
Operation and relationship expression
Relationship between operations is one of the simple logic operations, priorities for:
<=& gt;>===!=
Same (high) priority priority (low)
As a result of type bool value can only is true or false
For example: a> B, c<=a=b, x + y==3
It is the value of the Boolean type
Logic operation and logical expression
Logical operators
! (a) & amp; & (and) | | (or)
Low priority: high
Logic operation result types: bool, only for true or false
Logical expression
For example: (a> B) & amp; & (x> Y)
Boolean type

"& amp; & amp;" The algorithm of
On both sides of the expression is true, the result is true
There are side expression is false, the result is false
"& amp; & amp;" Characteristics of "short circuit" expression 1 & amp; & Expression of 2
To solve the expression 1
If an expression to a value to false, the final result to false
No longer to solve the expression 2
1 if the expression is true, the result of the solution expression
2 isIn expression results as the final result of 2

The operator "| |"
On both sides of the expression is true, the result is true
There are side expression is false, the result is false
"| |" "short-circuit characteristics" expression 1 & amp; & Expression of 2
To solve the expression 1
If an expression to a value to false, the final result to false
No longer to solve the expression 2
1 if the expression is true, the result of the solution expression
2 isIn expression results as the final result of 2

Conditional operator and conditional expression
General form

The expression 1? Expression is 2; Expression of 3
Expression must be bool type 1
Execution order
To solve the first express 1 value is true, then to solve the expression 2
2 the value of the expression for the final result
If the value of the expression 1 is false, is to solve the expression 3,
The value of the expression of 3 for the final result

Conditions for operation (expression 1? Expression 2:3) the priority of the
Conditional operator priority is higher than the assignment operator, below the logical operators
For example, x=a> b? A: b

1

2
Expression 1 is a bool type, the type of 2, 3 can be different, the final type of conditional expression was higher in 2, and 3


17.2.4.3 sizeof, bit operations
Sizeof is a kind of data type for a variable or his account for the number of bytes,
Advanced basic language processing data in bytes
Machine language, assembly language to deal with data in a
Sizeof operator, this is a calculate some type or a variable, an object he operation of how many bytes,
The Sizeof operator
Syntactic form
Sizeof (type) or Sizeof expression
The resulting value:
"Type name" specified type, or the result of the "expression" type of bytes
For example:
Sizeof (short)
Sizeof x

CodePudding user response:

Personal notes, advice on a personal blog
  • Related