C 中的 %d 和 %lf 有什么区别?
what's the difference between %d and %lf in C?
对于 c 中的 peintf,%d 和 %lf 有什么区别
printf("Value of n is %d\n", n);
printf("Value of x is %lf\n", x);
对于*printf
,
%d
用于将 int
类型的值包含为十进制数。
%lf
是在 C99 中引入的,作为现有 %f
.
的别名
%f
用于在样式 [-]ddd.ddd
.
中以十进制表示法包含类型 double
的值
cppreference.com 很棒 printf
reference.
用法示例:
int a_signed_int = ...;
signed char a_signed_char = ...;
short a_signed_short = ...;
double a_double = ...;
float a_float = ...;
printf("%d\n", a_signed_int);
printf("%d\n", a_signed_char); // `signed char`s are promoted to `signed int`s
printf("%d\n", a_signed_short); // Same for `signed short int`s
printf("%f\n", a_double);
printf("%f\n", a_float); // `float`s are promoted to `double`s
printf("%lf\n", a_double ); // Same as above.
printf("%lf\n", a_float); // Same as above.
对于 c 中的 peintf,%d 和 %lf 有什么区别
printf("Value of n is %d\n", n);
printf("Value of x is %lf\n", x);
对于*printf
,
%d
用于将 int
类型的值包含为十进制数。
%lf
是在 C99 中引入的,作为现有 %f
.
%f
用于在样式 [-]ddd.ddd
.
double
的值
cppreference.com 很棒 printf
reference.
用法示例:
int a_signed_int = ...;
signed char a_signed_char = ...;
short a_signed_short = ...;
double a_double = ...;
float a_float = ...;
printf("%d\n", a_signed_int);
printf("%d\n", a_signed_char); // `signed char`s are promoted to `signed int`s
printf("%d\n", a_signed_short); // Same for `signed short int`s
printf("%f\n", a_double);
printf("%f\n", a_float); // `float`s are promoted to `double`s
printf("%lf\n", a_double ); // Same as above.
printf("%lf\n", a_float); // Same as above.