Nothing to say, is + - / & =, == and the like.
Left and right values
Briefly summarized: when a target value is used as the right, with the value (memory) of an object; when the object is left as the value with the identity (location in memory) of an object. P is assumed that a type of int *, if acting on the decltype when an expression such as decltype (* p) obtained is a reference type, the result decltype (& p) is an int **
Operator Precedence
Logical and relational operators
Wherein the logic AND operator (&&) and logical OR (||) operator is shorted evaluation operators:
- For a logical AND operator, when and only true if left operand is evaluated only for the right operand.
- For a logical OR operator, when and only if left operand is false when evaluated on the right operand.
Assignment Operators
- Right assignment operator satisfies the associative law, i.e.,
|
|
- Calculating a lower priority assignment, it is in a conditional statement, the assignment portion is typically add brackets, such as:
cpp int i; while((i=get_value())!=42){ //anything }
Increment decrement operators
Minute pre-release and post-release. Pre-release before adding 1, then the object after the change as a result of the evaluation, post version will also add 1 operands, but the result is a copy of the evaluation before the operand values change.
If you want to test a true value arithmetic object or object pointer, the most direct approach is to condition it as if
|
|
When comparing operation unless the object of comparison is a Boolean type, do not use Boolean literals true and false as operands.
Member access operator
|
|
Conditional operator
? cond exprl: expr2
? example: String = finalgrade (Grade <60) "Fail": "Pass";
Grade <60 is true then take fail, then take false pass. The conditional operator precedence is too low, it may result in the following cases
|
|
Bitwise Operators
1 is the same or different exclusive 0
sizeof operator
sizeof operator returns the number of bytes occupied by one or expression of a type name, returns the value of a type size_t. Operator operand in two forms:
the sizeof (type)
the sizeof expr in the second form, sizeof returns the result of the expression of type sizes, the calculation is not calculated value of the object. sizeof operator results in part dependent on their type of action:
- Sizeof operation is performed on the expression of char or char type, the result obtained 1
- Sizeof operator performs reference to the type of the referenced object to obtain the size of the space occupied.
- Sizeof pointer performs arithmetic to obtain the size of the space occupied by the pointer itself
- Dereferencing the pointer to perform the sizeof object to obtain a pointer to the size of the space occupied by the pointer need not effective.
- Sizeof operation performed to obtain an array size of space occupied by the entire array, the array is equivalent to all of the elements and the operation is executed once sizeof summing the results obtained. Note that, sizeof operation will not be converted into an array of pointers to process.
- string and vector objects sizeof operation is performed on only the size of the return portion of fixed type, the object is calculated without the elements take up much space.
Comma operator
Comma operator contains two operands, left to right, are evaluated in order.
For comma operator, expression is evaluated first on the left, and then discard the evaluation result, the real result of the comma operator is the value of the expression on the right. If the right side is the left operand value, then the final result of evaluating the value is left.
Type Conversion
Implicit type conversion
Converted into an array of pointers: the most used expression array, the array automatically converted to point to the first element of the array pointer. When the array is used as a parameter decltype keyword, or taken as an address operator (&), sizeof operator and the like typeid operand when the conversion takes place. When initialized with a reference array to the conversion does not occur.
Pointer conversion: C ++ also provides several other pointer conversion mode, comprising a constant integer values 0 or literal nullptr can be converted into any pointer type; point to any great amount of a pointer can be converted to void *; point of any object pointers can converted into const void *.
Display conversion
Cast:
|
|
Note : Although sometimes have to use a cast, but the essence of this approach is very dangerous.
Mandatory conversion named: cast-name <type> (expression);
Here, type is the target type conversion and expression is the value to be converted. If the type is a reference type, the result is an lvalue. cast-name is a static_cast, dynamic_cast, const_cast and in reinterpret_cast.
static_cast:
Any type converter having a well defined, they do not contain the underlying const, may be used static_cast. For example, by a double operand type cast to perform floating-point division can make the expression;
|
|
const_cast:
const_cast can change the operand underlying const
|
|
Note: For converting const object to const object's behavior, we called a "remove const nature." Once we removed the const properties of an object, the compiler will no longer prevent the object we write a. If the object itself is not a constant, use a cast to get written permission is unlawful. However, if the object is a constant, and then use const_cast write operations will have undefined consequences. Only constant change const_cast property expression, the use of other forms of naming cast constant change property expression will lead to a compiler error. Similarly, nor can const_cast change the type of expression:
|
|
const_cast often used in the context of function overloading.
reinterpret_cast:
reinterpret_cast reinterpretation typically provided on the lower level bit pattern operands. For example, assume the following conversion
|
|
Old cast
In earlier versions of c ++ language, an explicit manner as cast comprising two forms:
type (expr); // function form casts
(Type) expr; // c language-style cast
Depending on the type involved, the old and have cast const_cast, static_cast reinterpret_cast or similar function. If the replacement is not legal, the old cast reinterpret_cast performs a similar function.
Original: Big Box C ++ primer study notes (c)