開放、平等、協(xié)作、快速、分享
浮點(diǎn)數(shù)格式控制符
int main(void)
{
//浮點(diǎn)數(shù)16進(jìn)制p-記數(shù)法
printf("浮點(diǎn)數(shù)p-記數(shù)法:%a\n", 100.0);
printf("浮點(diǎn)數(shù)p-記數(shù)法:%A\n", 123.0);
//浮點(diǎn)數(shù)e-記數(shù)法
printf("浮點(diǎn)數(shù)e-記數(shù)法:%e\n", 100.0);
printf("浮點(diǎn)數(shù)e-記數(shù)法:%E\n", 123.0);
//浮點(diǎn)數(shù)十進(jìn)制記數(shù)法
printf("浮點(diǎn)數(shù)十進(jìn)制記數(shù)法:%f\n", 123.0);
printf("浮點(diǎn)數(shù)十進(jìn)制記數(shù)法:%F\n", 123.0);
//根據(jù)數(shù)值不同自動選擇%f或%e
printf("浮點(diǎn)數(shù)自動記數(shù)法:%g\n", 123.0);
printf("浮點(diǎn)數(shù)自動記數(shù)法:%G\n", 123.0);
//long double型浮點(diǎn)數(shù)
printf("long double型浮點(diǎn)數(shù):%Lf\n", 123.0);
printf("long double型浮點(diǎn)數(shù):%LF\n", 123.0);
//浮點(diǎn)數(shù)小數(shù)點(diǎn)精度控制
printf("2位精度:%.2f\n", 3.14156);//3.14
printf("4位精度:%.4f\n", 3.14156);//3.1416
system("pause");
return 0;
}
整數(shù)格式控制符
int main(void)
{
int value = 0x12345678;
//無符號八進(jìn)制整數(shù)
printf("無符號八進(jìn)制整數(shù):%o\n", 123);
//char類型整數(shù)
printf("char類型整數(shù):%hhu\n", value);
printf("char類型整數(shù):%hhd\n", value);
printf("char類型整數(shù):%hhx\n", value);
//short類型整數(shù)
printf("short類型整數(shù):%hu\n", value);
printf("short類型整數(shù):%hd\n", value);
printf("short類型整數(shù):%hx\n", value);
//int類型整數(shù)
printf("int類型整數(shù):%u\n", value);
printf("int類型整數(shù):%d\n", value);
printf("int類型整數(shù):%x\n", value);
//long類型整數(shù)
printf("long類型整數(shù):%lu\n", value);
printf("long類型整數(shù):%ld\n", value);
printf("long類型整數(shù):%lx\n", value);
//long long類型整數(shù)
printf("long long類型整數(shù):%llu\n", value);
printf("long long類型整數(shù):%lld\n", value);
printf("long long類型整數(shù):%llx\n", value);
//intmax_t類型整數(shù)
printf("intmax_t類型整數(shù):%ju\n", value);
printf("intmax_t類型整數(shù):%jd\n", value);
printf("intmax_t類型整數(shù):%jx\n", value);
//ptrdiff_t類型整數(shù)
printf("intmax_t類型整數(shù):%tu\n", value);
printf("intmax_t類型整數(shù):%td\n", value);
printf("intmax_t類型整數(shù):%tx\n", value);
//size_t類型整數(shù)
printf("size_t類型整數(shù):%zd\n", value);
printf("size_t類型整數(shù):%zu\n", value);
printf("size_t類型整數(shù):0x%zx\n", value);
//windows平臺下專用說明符%I64,表示64位整數(shù)
printf("windows平臺64位整數(shù):%I64d\n", value);
printf("windows平臺64位整數(shù):%I64u\n", value);
printf("windows平臺64位整數(shù):0x%I64x\n", value);
system("pause");
return 0;
}
正數(shù)相關(guān)格式控制符
int main(void)
{
//使用+號且值為正的有符號數(shù)時(shí),在值前面顯示+號
printf("%+d\n", 10);//+10
printf("%+d\n", -12);//-12
printf("%+f\n", 10.0);
printf("%+f\n", -12.0);
//使用空格且值為正的有符號數(shù)時(shí),在值前面顯示空格
printf("% d\n", 10);// 10
printf("% d\n", -12);//-12
printf("% f\n", 10.0);
printf("% f\n", -12.0);
system("pause");
return 0;
}
字段寬度最小值
int main(void)
{
//最小長度為3,不足3則在左邊補(bǔ)充空格
printf("%3d\n", 12);
//最小長度為10,不足10則在左邊補(bǔ)充空格
printf("%10f\n", 0.1);
//最小長度為3,不足3則在左邊補(bǔ)充0
printf("%03d\n", 12);
//最小長度為10,不足10則在左邊補(bǔ)充0
printf("%010f\n", 0.1);
system("pause");
return 0;
}
int main(void)
{
printf("start=>%-8d<=end\n", 123);//start=>123 <=end
system("pause");
return 0;
}
其它格式控制符
int main(void)
{
//指針
int value = 100;
printf("指針:%p\n", &value);
//字符
printf("字符:%c\n", 0x33);
//字符串
printf("字符串:%s\n", "hello");
//百分號
printf("百分號:%%\n");
//八進(jìn)制整數(shù)前加上0
printf("%#o\n", 123);
//十六進(jìn)制整數(shù)前加上0x或0X
printf("%#x\n", 123);
//浮點(diǎn)數(shù)一定使用小數(shù)點(diǎn)
printf("%.0f\n", 1.0);
printf("%#.0f\n", 1.0);
system("pause");
return 0;
}
————————————————
版權(quán)聲明:本文為CSDN博主「土豆吞噬者」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/xiongya8888/java/article/details/89609748
24小時(shí)免費(fèi)咨詢
請輸入您的聯(lián)系電話,座機(jī)請加區(qū)號