C: transitive (double) assignments

后端 未结 6 1168
半阙折子戏
半阙折子戏 2021-01-20 07:11

I have used such construct in C:

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

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

<
6条回答
  •  梦毁少年i
    2021-01-20 07:46

    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.

提交回复
热议问题