Summary of Operators

1. Arithmetic operators

    {+、—、*/%  

    As long as there are floating-point numbers in the operands of the " / " operator, it performs floating-point division. The operand of " % " must be an integer.

2. Shift operator

    ( 1 ) left shift: << 

          "<<3" means that the binary bit is shifted to the left by 3 bits, and the right side is filled with 0 ; moving one bit has the effect of multiplying by 2 .

    ( 2 ) right shift: >>

         a. Arithmetic backward shift: the binary bit is moved to the right, discarded behind, filled with 1 on the left, and filled with the original sign bit on the left;

         b. Logical shift: The binary bits are shifted to the right, discarded behind, and filled with zeros on the left.

    Moving a digit has the effect of dividing by 2 .

3. Bit operators

    {&|^ 
         All three operands must be integers.

4. Assignment operator

    “=Used for variable creation, initialization, etc.; can reassign unsatisfactory values;

    Compound assignment is supported:
    “+=-=*=/=%=>>=<<=&=|=

    For example int x = 0;

                  x = x + 10;

                  x += 10  // compound assignment

5. Unary operator

    {!、+、—、&

    a. Unary operators have only one operand.

         b. & take the address

                    Int a = 10;

                    Int * pa=&a;    // Indicates that pa is a pointer variable, pointing to an integer variable

                    Int * * ppa = & pa;    //ppa is a secondary pointer

    The address of any variable can be taken;

    For arrays, when the array name exists alone, the array name represents the address of the first element of the array;

6. Relational Operators

    {> < >= <== ==

    Note: String comparison cannot use " >= , <= ".

7. Logical Operators

    Logical AND: && ;

    Logical NOT: || ;

8. Conditional operator

    Shaped like(expression1 ) ? (expression2 ) : (expression3 )

example:      
               if(a > 5)
                      b = 3 ;

                else

                      b = -3;

and

     a > 5? (b = 3) :(b = - 3);

equivalence.

 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325965816&siteId=291194637
Recommended