int main()
{
float n1 = 11.11;
double n2 = 222.222;
long n3 = 3333;
long n4 = 4444;
printf("Right: %f,%f,%ld,%ld\n",n1,n2,n3,n4);
printf("Wrong: %ld,%ld,%ld,%ld\n",n1,n2,n3,n4);
return 0;
}
其输出结果为:
root@BlueIris:~# ./printf_type
Right: 11.110000,222.222000,3333,4444
Wrong: -536870912,1076246609,-1614907703,1080805146
%f指示应该在内存中往后读8个字节,而%ld只有4个,因此出现偏差。
参考:深入printf
没有评论:
发表评论