zoukankan      html  css  js  c++  java
  • [面試題]C符號的優先順序

    • int x = 0;
      if (x = 0 || x == 0) printf("%dn", x);
      printf("%dn", x);  
    • 參考C的優先表, 其實就是if (x = (0 || x == 0))
      會printf出兩個1.

      同一优先级的运算符,运算次序由结合方向所决定。

      简单记就是:! > 算术运算符 > 关系运算符 > && > || > 赋值运算符

      C Operator Precedence Table

      This page lists C operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are 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 are also used to group sub-expressions to force a different precedence; such parenthetical expressions can be nested and are evaluated from inner to outer.
      Note 2:
      Postfix increment/decrement have high precedence, but the actual increment or decrement of the operand is delayed (to be accomplished sometime before the statement completes execution). So in the statement y = x * z++; the current value of z is used to evaluate the expression (i.e., z++ evaluates to z) and z only incremented after all else is done. See postinc.c for another example.
  • 相关阅读:
    基于Oracle的Mybatis 批量插入
    java.lang.ClassCastException: com.sun.proxy.$Proxy32 cannot be cast to com.bkc.bpmp.core.cache.MemcachedManager
    理解 Mybatis的分页插件 PageHelper
    手机注册获取验证码的PHP代码
    php分页代码简单实现
    PHP简单漂亮的分页类
    PHP实现各种经典算法
    Vue 入门指南 JS
    php 经典的算法题你懂的
    WebService 之 WSDL文件 讲解
  • 原文地址:https://www.cnblogs.com/bittorrent/p/4835201.html
Copyright © 2011-2022 走看看