Is scanf(“%d%d”, &x, &x) well defined?

前端 未结 3 2112
无人共我
无人共我 2020-12-01 23:29

Is the following code well defined?

#include 

int ScanFirstOrSecond(const char *s, int *dest) {
    return sscanf(s, \"%d%d\", dest, dest);
}         


        
3条回答
  •  渐次进展
    2020-12-02 00:05

    scanf() family functions execute the directions you leave them in the format string strictly in turn. So the first value will get read in, and then the second one, overwriting the first. Nothing UB here.

提交回复
热议问题