c++ - printf 对参数的顺序敏感吗?

标签 c++ printf zero

我想在 c++

中使用 printf 打印一行
    int t0 = time(NULL);
    int outIndx = 99736;
    printf ("time using recurision = %d secs, the result is = %d\n",(time(NULL) - t0), outIndx);

在这种情况下,printf 的输出是:

使用递归的时间 = 0 秒,结果为 = 0

但是当颠倒outIndx(time(NULL) - t0)的顺序时:

printf ("time using recurision = %d secs, the result is = %d\n", outIndx,(time(NULL) - t0));

printf 的输出被正确打印:

使用递归的时间 = 99736 秒,结果为 = 0

为什么会这样?

最佳答案

time 返回一个 time_t,它的大小不必与 int 相同。在这种情况下,%d 不是正确的输出格式。

关于c++ - printf 对参数的顺序敏感吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34411303/

相关文章:

Java项目返回空值

c++ - Hippo Mocks 中具有不同返回值的多个预期调用是否可以重复使用模拟?

c++ - cpp 文件中的部分特化不是 "well-formed"

c - 带有自定义注册说明符的 GCC snprintf

python - 如何删除包含零的 numpy 数组中的一行?

jsf - 如何使数字输入区域最初为空而不是0或0.00?

c++ - 解析日期失败

c++ - Opengl:2d HUD 超过 3D

Codeblocks 不打印特定格式

c++ - 在 printf 之后使用 fflush 会减慢你的程序吗?