#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; }
第二個(gè)輸出不是單精度嗎?為啥運(yùn)行結(jié)果是97.000000
第二個(gè)輸出不是單精度嗎?為啥運(yùn)行結(jié)果是97.000000
2017-08-03
舉報(bào)
2017-08-03
2017-08-03
#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)精確到小數(shù)點(diǎn)后第6位,雙精度(double--lf)精確到小數(shù)點(diǎn)后15位
2017-08-03
#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 在前面講解過小數(shù)的