是 scanf("%4s%4s", b, b); 定义明确?

6 c arrays scanf

#include <stdio.h>

int main(void) 
{
    char b[5];
    scanf("%4s%4s", b, b);
    //My input: "qwer<Enter>sgsh<Enter>"
    printf("%s", b);
    //Output: sgsh
}
Run Code Online (Sandbox Code Playgroud)

C99:在上一个和下一个序列点之间,对象最多应通过表达式的评估修改其存储的值一次。

在这种情况下,我正在修改b twice. 不是undefined behavior吗?

Som*_*ude 12

这个scanf参考

每个转换说明符的动作后都有一个序列点;这允许在同一个“接收器”变量中存储多个字段。

所以你正在做的事情是明确的,应该工作得很好。