zoukankan      html  css  js  c++  java
  • The type of assignment expression in C/C++, like (i = j) = k;

    int i = 1;
    int j = 2;
    int k = 3;
    (i
    = j) = k;
    这段代码会有什么结果?

    在C++中, i 的值是3

    在C中,这是一个编译错误: '=' : left operand must be l-value

    参看他们的标准

    In ISO C++ 2003, 5.17 Assignment operators

    1 There are several assignment operators, all of which group right-to-left. All require a modifiable lvalue as their left operand, and the type of an assignment expression is that of its left operand. The result of the assignment operation is the value stored in the left operand after the assignment has taken place; the result is an lvalue.
     

    In C99 6.5.16 Assignment operators
    3 An assignment operator stores a value in the object designated by the left operand. An assignment expression has the value of the left operand after the assignment, but is not an lvalue. The type of an assignment expression is the type of the left operand unless the left operand has qualified type, in which case it is the unqualified version of the type of the left operand. The side effect of updating the stored value of the left operand shall occur between the previous and the next sequence point.

    4 The order of evaluation of the operands is unspecified. If an attempt is made to modify the result of an assignment operator or to access it after the next sequence point, the behavior is undefined.

  • 相关阅读:
    界面版按键精灵的使用【包含内置浏览器、打开程序的方法】
    按键精灵【找图片,并打开该图或打开且关闭两段代码】
    tomcat零碎知识点
    windows server 2008运维
    上传文件与读取文件列表以及创建文件
    Tomcat和win2008运维常识及方法
    Linux权限问题
    Summary
    iOS 高阶
    iOS
  • 原文地址:https://www.cnblogs.com/aoaoblogs/p/1910410.html
Copyright © 2011-2022 走看看