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.

  • 相关阅读:
    C# UrlDecode将+替换为空格问题
    Hashtable无序,用Dictionary代替
    Oracle查找Web执行SQL
    远程连接Oracle服务器
    asp.net core网站SSL nginx配置
    Supervisor踩过的坑
    centos nginx配置支持WebSocket(signalR)
    SignalR在asp.net core下使用
    Hangfire 在asp.net core环境的使用
    liteUploader上传控件的封装使用
  • 原文地址:https://www.cnblogs.com/aoaoblogs/p/1910410.html
Copyright © 2011-2022 走看看