问题printf函数? [英] problem with printf function?

查看:71
本文介绍了问题printf函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了下面的程序

 #include <stdio.h>

 main()
 {
 int i = 2;
 float c = 4.5;
 printf("%d\n",c);
 printf("%f\n",i);
 return 0;
 }

虽然我知道这是错误的做法,当我运行程序我得到了答案

though i know this is the wrong practice,when i run the program i got the answer as

0
4.500000

但是当我交换的printf的语句有点这样

but when i exchanged the printf statements a little bit this way

#include <stdio.h>

main()
{
int i = 2;
float c = 4.5;
printf("%f\n",i);
printf("%d\n",c);
return 0;
}

产量为

0.000000
0

我不明白发生了什么,任何一个请解释我。

i couldn't understand whats happening ,any one pls explain me.

推荐答案

的printf不转换它的参数。它在寻找记忆含有浮标,并打印出来,好像它是一个整数 - 这就像一个MP3文件,并要求字来打开它,仿佛它是一个文档

printf doesn't convert it's arguments. It's looking at the memory containing a float and printing it as if it were an integer - it's like taking an MP3 file and asking word to open it as if it were a doc.

一个浮点数存储在一个完全不同的方式在存储器中的整数 - 它不只是一些小数点的整数

A floating point number is stored in a completely different way in memory to an integer - it's not just an integer with some decimal points

这篇关于问题printf函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆