[Face problem] The first order of C symbols

Source: Internet
Author: User
Tags arithmetic operators modulus

  • int x = 0;if (x = 0 | | x = = 0) printf ("%dn", x);p rintf ("%dn", X);
  • The priority table for reference C is actually if (x = (0 | | x = = 0))
    Will printf out two 1.

    Operators of the same precedence, the order of operations is determined by the binding direction.

    Simple note is:! > Arithmetic operators > Relational operators > && > | | > Assignment Operators

    C Operator Precedence Table
    This
    page lists C operators the order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression is applied.

    Operator

    Description

    Associativity

    ( )
    [ ]
    .
    -
    ++ --
    Parentheses (function call) (see Note 1)
    Brackets (array subscript)
    Member selection via object name
    Member selection via pointer
    Postfix increment/decrement (see Note 2)

    Left-to-right

    ++ --
    + -
    ! ~
    (type)
    *
    &
    sizeof
    Prefix increment/decrement
    Unary Plus/minus
    Logical Negation/bitwise Complement
    Cast (convert value to temporary value of type)
    Dereference
    Address (of operand)
    Determine size in bytes on this implementation
    Right-to-left
    *  /  % Multiplication/division/modulus Left-to-right
    +  - Addition/subtraction Left-to-right
    << >> Bitwise shift left, Bitwise shift right Left-to-right
    < <=
    > >=
    Relational less than/less than or equal to
    Relational greater than/greater than or equal to
    Left-to-right
    ==  != Relational is equal to/is not equal to Left-to-right
    & Bitwise and Left-to-right
    ^ Bitwise Exclusive OR Left-to-right
    | Bitwise inclusive OR Left-to-right
    && Logical and Left-to-right
    | | Logical OR Left-to-right
    ? : Ternary conditional Right-to-left
    =
    +=  -=
    *=  /=
    %= &=
    ^=  |=
    <<= >>=
    Assignment
    Addition/subtraction Assignment
    Multiplication/division Assignment
    Modulus/bitwise and Assignment
    Bitwise exclusive/inclusive OR Assignment
    Bitwise Shift Left/right Assignment
    Right-to-left

    Comma (separate expressions) Left-to-right
    Note 1:
    parentheses A Re also used to group sub-expressions to force a different precedence; Such parenthetical expressions can be nested and is evaluated from inner to outer.
    Note 2:
    Postfix increment/decrement has high precedence, but The actual increment or decrement of the operand is delayed (to be accomplished sometime before the statement completes E xecution). So in the statement  y = x * z++;  the Current value of  z  is used to evaluate the expression ( i.e., &nbs P z++  evaluates to  z ) and  z  only incremen Ted after all else was done. see  postinc.c  for Another example.

The priority order of the]c character of the polygon question

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.