C: transitive (double) assignments

后端 未结 6 1162
半阙折子戏
半阙折子戏 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条回答
  •  生来不讨喜
    2021-01-20 07:33

    it's multiple assignment as your first option is the right one

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

    it's a magic of flow.

    initially ,tail is set to NULL ,starting from right to left

    list->tail = NULL;
    

    then list->head = list->tail ;

    now tail is NULL so the head will also assigned a NULL value

提交回复
热议问题