当 scanf(fscanf) 遇到 EOF 时,参数变量中存储的值是多少?

What's the value stored in the argument variable when scanf(fscanf) encounters EOF?

int *ptr = malloc~
while (fscanf(fp, "%d", ptr++) != EOF)
    ;

假设有足够的内存分配给 ptr, 当函数encouters EOF 指示时,*ptr 中存储的值是什么? 我尝试在 Visual Studio 中使用调试工具,发现 *ptr 的值为 -33686019 这是垃圾值吗?还是 EOF?

当 scanf 到达 EOF 时,没有值存储 在地址 ptr 指向。 同样,如果它 returns 0。这就是为什么迭代输入的规范方法必须检查 scanf return 值的原因,例如与

if (fscanf(fp, "%d", &ptr_to_int) == 1) {
  /* successful conversion */
}
else {
  /* Unsuccesful conversion or EOF; use feof() to test which. */
}