Source: Internet
Author: User

The previous section describes the bitwise operators in C + +, and this section continues to learn about other operators in C + +. To deepen the understanding of the various operators.

Self-、--self-reduction of 1.++

This operator can be divided into both front and back forms. The so-called predecessor, is the operator in front of the operand, the post is the operator after the operand. Here, the two are still very different. Emphasis: The post operator has precedence over the predecessor operator

For example: i++; Post-placement

--j; Predecessor

Rule: In the operation, the predecessor is the first change after the operation, after the first operation after the change.

For example: predecessor form

int i=5; X=++i; Y=i//I must first increment and then pay X, that is, first change, after operation (I=6, x=6, y=6)

int i=5; ++i; X=y=i//(I=6, y=6, x=6)

Post form

int i=5; x=i++; Y=i; I first assign the value to X, plus 1

2, conditional operator

Form: D1?d2:d3, the only three-mesh operator in C + +

Rule: 1. Calculate D1 First

2. If the value of D1 is true, return the value of D2 as the result

3. If D1 is false, return the value of D3 as the result

3. Comma operator

form: expression 1, expression 2, expression 3 ...

Rule: First evaluate the value of expression 1, then the value of expression 2, and so on, and so on, the entire comma expression result is the value of the last expression

4. Byte-Seeking operators

Form: sizeof (type specifier | variable name | constant)

Rule: The number of operands is determined by the operand type, which occupies the memory size.

5. Member Operators

The C + + language provides operators that indicate array elements, structs, and union members.

For example: subscript operator [], through the pointer structure or the Federation member operator-->

6, take the address operator

Form:& variable Name

Rule, which is the value of the memory cell address used to get a variable.

For example,:& a represents the address value of variable A, which can usually be used before various variable names, such as array element names, structure variables, and so on. Cannot function before a constant, non-left value expression, because the second expression has no memory address.

7, fetch the pointer content operator

form: * int a=5; The value in the memory unit identified by INT * p=& A//variable A is 5, and the pointer variable p points to variable A, which acts on P (that is, * p), and the final *p result is 5.

These are some of the more specific operators I have encountered in learning C + +.

Related Article