About operators (the three-mesh operator) and the precedence relationship in the operation process

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise bitwise operators logical operators lowercase

turn from: http://blog.csdn.net/dingliqin/article/details/6490986

Priority ━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━ expressions for Turbo C operators ┃ priority ———————————————————————————— ╂ ———— () (parentheses) [] (array subscript). (struct member)-> (member of a pointer structure) ┃ highest ———————————————————————————— ┃↑! (Logically not). (Bit counter)-(minus) + + (plus 1)-(minus 1) & (variable address) ┃│ ———————————————————————————— ┃│* (pointer) type (function description) size                                                               of (length calculation) ┃│ ———————————————————————————— ┃│* (multiply)/(except)% (remainder)                                                                               ┃│ ———————————————————————————— ┃│+ (add)-(minus) ┃│ ———————————————————————————— ┃│<< (left-shift) ;> (bit right shift) ┃│ ———————————————————————————— ┃│< (less than) & Lt;= (less than or equal to) > (greater than) >= (greater than or equal) ┃│ ———————————————————————————— ┃│ 
     = = = (equal to)!= (not equal to) ┃│ ——————————————————————————— -┃│& (bit and) ┃│ ———————                                                                                    ————————————————————— ┃│^ (XOR) ┃│ ———————————————————————————— ┃│| (bit or) ┃│ ——————————————————————— ————— ┃│&& (logic and) ┃│ ———— ———————————————————————— ┃│| | (logical OR) ┃│ —————————————————————————— --┃│:(?  expression) ┃│ ———————————————————————————— ┃                    │= + = = (Federated operation)                                              ┃│ ———————————————————————————— ┃│, (comma operator) ┃ minimum C-language operator Priority Turbo C is very rich in operators, mainly divided into three categories: arithmetic operators, relational operators and logic operator, bitwise operator. In addition, there are operators to accomplish special tasks. 

    The following are described separately. The arithmetic operators of the 5.1 arithmetic operator Turbo C are as follows: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ operator function ———————————————————                             ————————— + Plus, one eye take positive-minus, one eye take negative *                           Multiply/divide% modulo-- Minus 1 + + 1━━━━━━━━━━━━━━━━━━━━━━━━━━━━ one or one mesh and two mesh operation one eye Doing is the operation of an operand. 
    For example:-A is a one-eye negative operation on a. 
    A binary operation (or a multiple-eye operation) is an operation of two operands (or operands). In Turbo C, the addition, subtraction, multiplication, addition, modulo operation is the same as other advanced languages. 
    You need to be aware of division and modulo operations. 
For example: 15/2 is 15 divided by 2 quotient of the integer Part 7 15%2 is 15 divided by 2 of the remainder part 1 for modulo operator "%", cannot be used for floating-point numbers.    In addition, since the number of characters in Turbo C is automatically converted to an integer, the number of characters can also participate in the two-mesh operation.     For example: Main () {char m, n;         /* Define the character type variable * * m= ' C ';   /* Give M a small letter ' C '/n=m+ ' a '-' a '; 
    /* Convert lowercase letters in C to uppercase ' B ' and assign to n*/...} In the example above, m= ' C ' is m=98, because the ASCII values of letters A and A are 65 and 97, respectively. 


    This turns lowercase letters into uppercase letters, whereas if you want to turn uppercase letters into lowercase letters, you can use c+ ' a '-' a ' to calculate them. Two, incremental operations have two very useful operators in Turbo C, which are not usually available in other high-level languages. 
    These two operators are the 1 and minus 1 operators "+ +" and "--", the operator "+ +" is the operand plus 1, and "--" is the operand minus 1. For example: X=x+1 can be written as x + +, or ++x x=x-1 can be written either as ×--, or--x + + + (x--) and ++x (--x) in the previous example, but x=m++ and X=++m have a great 
      Difference. 
      x=m++ means that the value of M is assigned to X, and M plus 1. 


    X=++m says M first adds 1, then assigns the new value to X. 
    The data type conversion type conversion in an assignment statement is a type change in which different types of variables are mixed. 
    In an assignment statement, the type conversion rule is: The value to the right of the equal sign is converted to the type of the variable to the left of the equal sign.      For example: Main () {int i, J;    /* Define integer variable */float f, g=2.58;         /* Define floating-point variable */f=i*j;           The product of/*i and J is an integer number, which is transformed into a floating point to assign to f*/i=g; 
    The floating-point number in the/*g is converted to the integer number assigned to i*/...} Because TurBo C converts rules by the data type described above, so special attention should be paid to division operations. 
          For example: Main () {float F; 
          int i=15; 
     F=I/2; F=7 is not equal to the exact value of 7.5 after the above program is run. 
          The correct program should be: Main () {float F; 
          int i=15; 
     f=i/2.0; 


    You can also define I directly as a floating-point number. 
    5.2 Relational operators and logical operators one, logical operator logical operators refers to the use of formal logic principles to establish the relationship between the number of symbols. 
          The logical operators of Turbo C are as follows: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ operator Action —————————————————————————————                          && Logic and | |                           Logic or! 
    Logical non-━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ two, relational operator relational operators are symbols that compare the size of two operands. 
          The relational operators of Turbo C are as follows: The ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ operator functions —————————————————————————————                               > greater than >= greater than or equal to <  Less than <= equals = = =                           equals!= not equal to ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ relational operators and logical operators The key is true (true) and False (false) concepts. True in Turbo C can be any value that is not 0, and false is 0. 
    When using relational operators and logical operator expressions, returns 1 if the expression is true (that is, true), or 0 if the expression is false (that is, false). For example: 100>99 returns 1 10> (2+10) returns 0!1&&0 return 0 to the above example expression!1&& 0, First! 1 and the first 1&&0 will be equal to a different result, then what is the priority? This is provided for in Turbo C. 


    Precedence about operators is described later in this section. 5.3 bitwise operator Turbo C differs from other advanced languages in that it fully supports bitwise operators. 
    This is somewhat similar to the bit operation of assembly language. 
          The bitwise operators in Turbo C have the following functions: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ operators ————————————————————————————                        &-Logic and |                         Bit logic or ^ bit logical xor or-bit logic anti->> Move right << left ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ bitwise operation is to detect, set, or shift the actual bits in a byte or word, it Applies only to character and integer variables and their variants, to other dataType does not apply. The result of relational and logical operation expressions can only be 1 or 0. 
    The result of bitwise operations can be a value other than 0 or 1. 
    Be aware of the difference between bitwise and logical operators, for example, if x=7, the X&&8 value is true (two non-0 values are still not 0), and the X&8 value is 0. 
    The shift operator ">>" and "<<" refers to moving each digit in a variable to the right or left, usually in the form of: Right Shift: Variable name >> shifted number of digits left: variable name << shifted digits 
    After the shift, the bits at one end are "squeezed out" and the vacated bits on the other end are filled with 0, so the shift in Turbo C is not circular. 5.4 Turbo C Special operators One, "?" Operator "?" 
    The operator is a three-mesh operator, and its general form is: < expression 1>?< expression 2>:< expression 3>; "?" The meaning of an operator is to first evaluate the value of expression 1 and, if true, the value of expression 2 and use it as the value of the entire expression; 
    If the value of expression 1 is false, the value of the expression 3 is evaluated and used as the value of the entire expression. 
          For example: Main () {int x, y; 
          x=50; 
     y=x>70?100:0; In this case, Y will be assigned a value of 0. 
    If x=80, Y will be assigned a value of 100. So, "?" 


    Operators can replace statements in some if-then-else form. 
    The "&" and "*" operator "&" operator is a single eye operator that returns an operand address. 
    The "*" operator is a supplement to the "&" operator, which returns the value of the variable at this address and is also a monocular operator. 
          For example: Main () {int I, j, *m; 
          i=10;          m=&i;          /* Assign the address of the variable i to m*/j=*m; 
     /* Address m refers to the value of the cell assigned to j*/After the above program runs, i=10, M is its corresponding memory address, and J has a value of 10. 
    The "," "operator", "operator" is used to string together multiple expressions, the left side of the "," operator is not always returned, and the value of the right expression is the value of the entire expression. 
          For example: Main () {int x, y; 
          x=50; 
     Y= (x=x-5, X/5); 
  


    The Y value is 9 after the above program executes because the initial value of X is 50, minus 5, then 45, and 45 is assigned to Y except 5. 
    The sizeof operator sizeof operator is a monocular operator that returns the byte length of a variable or type. 
     For example: sizeof (double) is 8 sizeof (int) is 2, you can also ask for a defined variable, for example: float F; 
     int i; 
    I=sizeof (f); 


    The value of I will be 4. V. Joint Operation Turbo C has a special shorthand for simplifying an assignment statement for all the binocular operators. 
      Its general form is: < variable >=< variable >< operand >< expression > equivalent to < variable >< operand >=< expression > For example: A=a+b can be written as A+=b a=a&b can be written a&=b a=a/(b-c) can be written in A/=b-c 5.5 Turbo c operator Priority Turbo C prescribes the precedence of operators. When more than one operator in an expression participates in an operation, the precedence specified in the following table is performed. 
    The precedence of the table is lowered from top down and the same row priority is the same. For example: an expression 10>4&&! (100<99) | | The value of 3<=5 is 1 expression 10>4&&! (100<99) &AMP;&AMP;3&LThe value of t;=5 is 0  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.