[面試題]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.
时间: 2024-08-28 12:26:34

[面試題]C符號的優先順序的相关文章

香港小學一年級入學考試題

據說小学生几秒就做出:高中生几分钟:大学生半小时以上:博士可能要一辈子...... What takes an elementary school student just seconds to do; takes a high school student several minutes; takes a college student half and hour and up; and takes a Ph.D a lifetime- 請看題: the question is: 來源: ch

Java面試題(实用性高)

3.Spring MVC中的注解你都用过哪些,SpringMVC的运行原理是什么? @Controller:使其普通的java类充当控制层的作用. @RequestMapping:有两个参数 url 代表要访问的路径 method请求方式 @Service::使其java类充当service层. @Repository::使其java类充当持久层. @Resource:默认按照名字注入指定的bean. @Autowired:默认按照类型进行注入可以结合@Qualifier("bean的的名字 名

130面試題

简述 private. protected. public. internal 修饰符的访问权限. 答: l  private : 私有成员, 在类的内部才可以访问. l  protected : 保护成员,该类内部和继承类中可以访问. l  public : 公共成员,完全公开,没有访问限制. l  internal: 在同一命名空间内可以访问. 列举ASP.NET 页面之间传递值的几种方式. 答. l  使用QueryString, 如....?id=1; response. Redirec

.net面試題

初级.NET开发人员 - 任何使用.NET的人都应知道的 1. 描述线程与进程的区别? 进程是系统所有资源分配时候的一个基本单位,拥有一个完整的虚拟空间地址,并不依赖线程而独立存在.进程可以定义程序的一个实例,但它只是占据应用程序所使用的地址空间.为了让进程完成一定的工作,进程必须至少占有一个线程,这个线程即为主线程,默认程序的工作都在这个主线程中完成,可以通过程序创建多个线程,使多个线程可以同时运行(多CPU支持下),这就是多线程技术. 线程(Thread)与进程(Process)二者都定义了

給出一個數,倒序輸出它,符號也要考慮,使用整除10和對10的模運算很方便,同時也知道了越界的計算方法

class Solution {public: int reverse(int x) { int rev = 0; while (x != 0) { int pop = x % 10; x /= 10; if (rev > INT_MAX/10 || (rev == INT_MAX / 10 && pop > 7)) return 0; if (rev < INT_MIN/10 || (rev == INT_MIN / 10 && pop < -8)

面試題匯總

1.a = 1 b =2 用一行代碼顯示a = 2 b = 1 a = 1 b = 2 a, b = b, a print(a, b) 原文地址:https://www.cnblogs.com/yvz5414/p/10182894.html

JavaScript基礎知識

1.標籤組使用 <script charset='utf-8' //設置字元集 defet //使腳本延遲到文檔解析完成,Browser已忽略 language='javascript' //設置語言,已廢棄 src='url' //引用外部檔,可選 type='text/javascript' //必選,language替代品 >代碼</script> 列印JavaScript結尾符(外部引用可直接打):'<scr'+'ipt>'); src引用JS後,不要在<

數據分析能力的8個等級

並非所有的分析方法作用都相同.和大多數軟體解決方案一樣,你會發現分析方法的能力也存在差異,從簡單明了的到高級複雜.下面我們按照不同分析方法所能給人帶來的智能程度,把分析能力劃分為8個等級. 1. 固定財務報表 回答: 發生了什麼?什麼時候發生的? 示例:月度或季度財務報表 我們都見過報表,它們一般是定期生成,用來回答在某個特定的領域發生了什麼.從某種程度上來說它們是有用的,但無法用於制定長期決策. 2. 即席查詢 回答:有多少數量?發生了多少次?在哪裡? 示例:一周內各天各種門診的病人數量報告.

sublime Text3及其插件的使用

参考:Sublime Text 3 新手上路:必要的安裝.設定與基本使用教學 Sublime Text 相信是許多開發人員人心目中的最愛,然而對一個 Sublime Text 3 的新手來說,有什麼是在第一次使用時一定要了解的事情呢?我整理了幾個重要步驟,幫助大家快速上手,並在文末加上幾個不錯的參考連結,供大家進一步學習這套工具的使用. 安装与注册 基本安裝我想不用特別說明了,直接到官網下載相對應的版本,裝起來就對了. 然后需要注册码来去除未注册的提示! 注册码: ----- BEGIN LIC