Is the output of printf (“%d %d”, c++, c); also undefined?

后端 未结 6 475
予麋鹿
予麋鹿 2020-11-27 07:25

I recently came across a post What is the correct answer for cout << c++ << c;? and was wondering whether the output of

int c = 0;  
printf (         


        
6条回答
  •  遥遥无期
    2020-11-27 07:54

    The behavior of the program is undefined because it has violated the requirements of 6.5 Expressions:

    Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.

    c++ and c are both evaluated without an intervening sequence point, and the prior value of c is read both to determine the value to be stored by c++, and to determine the value of the expression c.

提交回复
热议问题