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.

  • 相关阅读:
    oracle 存储过程
    IBM Http Server 7 下载安装
    设置linux静态IP地址
    was7补丁下载安装
    JDBC提供程序和数据源配置
    db2替换激活永久lic
    db2基本命令
    db2创建数据库
    linux解压命令
    linux下安装db2_v9.7
  • 原文地址:https://www.cnblogs.com/aoaoblogs/p/1910410.html
Copyright © 2011-2022 走看看