Does 'a[i] = i;' always result in well defined behaviour?

后端 未结 6 1407
忘了有多久
忘了有多久 2021-02-05 11:19

There are several interesting questions raised here regarding undefined behaviour in C. One of them is (slightly modified)

Does the following piece of code r

6条回答
  •  清歌不尽
    2021-02-05 11:47

    int i = 0, *a = &i;

    there is a sequence point between declarations, therefore no UB here. However take a note that it is a bad idea to declare/define variables that way. Any normal coding standard would tell you declare one variable per line.

    a[i] = i;

    The i is not changed in any way, therefore no UB here either.

提交回复
热议问题