C:传递(双)分配 [英] C: transitive (double) assignments

查看:100
本文介绍了C:传递(双)分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C中使用这样的结构:

 列表 - >头=列表 - >尾= NULL;

现在我考虑这是否真正意味着什么,我想。

时这意味着什么?


  1. 列表 - >头= NULL;列表 - >尾= NULL;

<醇开始=2>
  • 列表 - &GT;头=列表 - &GT;尾;列表 - &GT;尾= NULL;

  • THX澄清


    解决方案

    这些都不是正确的。

    由于简单的赋值 = 操作符是从右到左结合,你的前pression是相同的:

     列表 - &GT;头=(列表 - &GT;尾= NULL);

    NULL被分配到尾,然后尾部,其中有一个空指针的值,到头部。

    I have used such construct in C:

    list->head = list->tail = NULL;
    

    and now I consider whether this really mean what I suppose.

    Is this mean?

    1. list->head = NULL; list->tail = NULL;

    or

    1. list->head = list->tail; list->tail = NULL;

    thx for clarifying

    解决方案

    Neither of those is correct.

    Since the simple assignment = operator is right-to-left associative, your expression is identical to:

    list->head = (list->tail = NULL);
    

    NULL is assigned to tail, and then tail, which has the value of a null pointer, to head.

    这篇关于C:传递(双)分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆