为了账号安全,请及时绑定邮箱和手机立即绑定

#include <stdio.h> int main() { char c = 'a'; int n = c ; //将c赋值给n float f = c; //将c赋值给f double d = c; //将c赋值给d printf("%d\n",n); printf("%f\n",f); printf("%lf\n",d); return 0; }

第二个输出不是单精度吗?为啥运行结果是97.000000

正在回答

4 回答

int类型赋值的时候是不用加引号的

cvzwzrvpyfhlitakpdyrkvzqqt

0 回复 有任何疑惑可以回复我~
这里的精度指的是有效数字的位数,后面的零都是为了区别于整型的,所以默认是那么多个,


0 回复 有任何疑惑可以回复我~

#include <stdio.h>

int main() 

    char c = 'a'; 

    int n = c ;   //将c赋值给n 

    float f = c;   //将c赋值给f 

    double d = c;   //将c赋值给d 

    printf("%d\n",n); //97

    printf("%f\n",f); //97.000000

    printf("%lf\n",d);//97.000000000000000

    return 0;

}

单精度(float--%f)精确到小数点后第6位,双精度(double--lf)精确到小数点后15位

0 回复 有任何疑惑可以回复我~
#1

ICQ小乐乐

单精度(float--%f)精确到小数点后第6位,双精度(double--%lf)精确到小数点后15位
2017-08-03 回复 有任何疑惑可以回复我~
#2

Jo丶 回复 ICQ小乐乐

为什么你这个没写a等于多少却可以输出97
2017-09-15 回复 有任何疑惑可以回复我~
#3

ICQ小乐乐

回复 Jo丶因为c赋值给n,而c=‘a’,由于n的类型是int,所以被强制转换了,a的ASCII码对应的值是97
2017-09-15 回复 有任何疑惑可以回复我~

#include <stdio.h>

int main()

{

    char c = 'a';

    int a =97;

    int n = c;         //将c赋值给n

    float f = c;       //将c赋值给f

    double d = c;      //将c赋值给d

    printf("%d\n",n);

    printf("%f\n",f);

    printf("%lf\n",d);

    return 0;    

}

%f 在前面讲解过小数的

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

#include <stdio.h> int main() { char c = 'a'; int n = c ; //将c赋值给n float f = c; //将c赋值给f double d = c; //将c赋值给d printf("%d\n",n); printf("%f\n",f); printf("%lf\n",d); return 0; }

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信