Home > database >  The second chapter C
The second chapter C

Time:10-18

Comma operation and comma expression
The format
The expression 1, 2

To solve the order and the results
To solve the expression 1 first, then to solve the expression 2 final result with the value of expression 2

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)
Relational expression is one of the most simple logical expression
As a result of type bool value can only is true or false
For example: a> B, c<=a + b, x + y==3

Logic operation and logical expression
Logical operators
Priorities:
! (a) high
& & (and)
| | (or low)

Logic operation result types: bool, values can only is true or false
Logical expression
For example: (a> B) & amp; & (x> Y)


"& 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;" "Short circuit characteristic expression of 1 & amp; & Expression of 2, first to solve the expression 1
If the value of the expression 1 to false, no longer to solve the end result is false expression 2
1 if the expression is true, the result of the solution expression, 2 is to expression results as the final result of 2
The operator "II"
On both sides, expression is false, the result is false, there are on one side of the expression is true, the result is true

"II" short circuit "features" expression 1 2 I expression, to solve the expression 1
1 if the expression evaluates to true, then the final result to true solution expression no longer 2
If expression 1 to false, the results of the solution expression to expression 2 results as the final result of the


Conditional operator and conditional expression

General form
The expression 1? Expression 2:3. Expression must be bool type 1

Execution order
To solve the expression 1 first,
1 if the expression evaluates to true, to solve the expression, 2 is 2 the value of the expression for the final result
If the value of the expression 1 to false, solving 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
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

The sizeof operator
Syntactic form
Sizeof (type) or sizeof expression

, the result value:
"Type name" specified type, or the result of the "expression" type of the number of bytes,
Example:
Sizeof (short)
Sizeof X

Computing a bitwise and (& amp; )
Algorithm
Two computational complexity of every position by using the Boolean and operator

Example: calculate 3 & amp; 5
3:00 000011
5:00 000101
-- -- -- -- -- -- -- -- -- --
3 & amp; 5:00 000001

Bit operations bitwise or (|),
Algorithm
Two computational complexity of every position by using the Boolean or operator
Example: computing
3:00 000011
5:00 000101
-- -- -- -- -- -- -- -- -- -- --
3 | 5:00 000111
Use, for example:
Certain position 1, other unchanged
For example: int variable a low byte buy 1:
A=a | 0 XFF

A computing a bitwise xor (^)
Algorithm
Exclusive or two operands:
If the corresponding bit is the same, if the bit is 0 corresponds to a different result, the bit is 1 the results

Example: 071 ^ 052
071:01111001
052:00101010
-- -- -- -- -- -- -- -- -- -- --
071 ^ 052:00010011

Bit operations - the not (~)
Operator:
Unary operators, for a binary number by the the end of a case:
025:0000000000010101
~ 025:1111111111 101010

An arithmetic shift (& lt; <, & gt;> )
Left shift operation (& lt; <)
After left shift, low fill 0, high abandon
Moves to the right operation (& gt;> )
After moves to the right:
Low:
Give up high:

Unsigned number: fill 0
A signed number: fill "the sign bit
"
Mixed operation data type conversion when an implicit conversion
- some binary operator (arithmetic operators, relational operators, logical operators,
An operator and the assignment operator) requires two operands of type - to

If the cords in the arithmetic operations and relations with arithmetic operand type is not consistent,
Build system automatically the data conversion (that is, the implicit conversion), the basic principle is to low type data into high type data

Mixed operation data type conversion when
A non Boolean type arithmetic values assigned to Boolean type, arithmetic value of 0,
Results to false, otherwise the result is true
To assign a Boolean value to a Boolean type, Boolean value to false, the result is 0
Boolean value of true the result is 1

Mixed operation data type conversion when
To assign a floating points to integer types, the value will only keep floating point Numbers of
The integer part and decimal part will lose
To assign an integer value to floating point types, the decimal part down to zero, if the integer
Of space more than the capacity of the floating point types, precision may be loss

Mixed operation data type conversion when _ explicit conversion
The effect of explicit type conversion is the result of the expression type conversion for
The type specifier specified type
Syntactic form
The type specifier (expression) (type specifier) expression
Type conversion operator & lt; The type specifier & gt; (expression)
Const cast, dynamic cast, reinterpret cast, static. Cast

Mixed operation data type conversion when _ explicit conversion
Grammar form in the form of C + +
Type conversion operator & lt; The type specifier & gt; (expression)
Type conversion operator can be:
Const_cast dynamic_cast reinterpret_cast static_cast
Example: int (z), z (int), the static cast & lt; Int> (z) three completely equivalent

Annotation methods:
Methods a
Extended C method, the use of "/*" and "*/" quoted text;
Method 2
Use "//", from "1/", until it is in line with the tail, all characters are as the annotation processing,

Runtime error of the main two reasons:
Type and logic is wrong
  • Related