好的。这一定是我遇到的最奇怪的错误之一。我的代码中有这两行
int id=i*2000*512+512*row+column;
if (id==1){printf("This is output %f %f %f %i \n",entire_red[id],entire_green[id],entire_blue[id],id);}
它给了我输出
This is the output 0.000000 0.000000 0.000000 109456488.
我不知道发生了什么!
最佳答案
%f
格式说明符需要一个 double
(float
隐式转换为 double
用于可变参数函数) .如果 variable_red
等不是 float
或 double
变量,则 printf
将错误地处理参数,并且可以解释为什么 id
整数打印不正确。
试试这个:
if (id==1)
printf("This is output %f %f %f %i\n", (double)entire_red[id],(double)entire_green[id],(double)entire_blue[id],id);
或者,确保为 entire_red
、entire_green
和 entire_blue
变量使用正确的格式说明符。
关于c - if (id==1) printf ("%i", id) 打印一些随机值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5213537/