printf 各种参数总结
来源:互联网 发布:耐思尼克域名注册平台 编辑:程序博客网 时间:2024/06/05 10:05
The syntax for a format placeholder is
%[parameter][flags][width][.precision][length]specifier
printf("example like %3$lf, %3$-10.5lf, %2$.5s, %1$-10d.\n", 123456, "abcdefghigk", m);
specifier
</pre><pre name="code" class="cpp"> // %d or %i unsigned int a = 2147483647 + 5; int b = -5; printf("signed decimal integer like %d, %i.\n", a, b);//wrong with a, ok with b // %u printf("unsigned decimal integer like %u, %u.\n", a, b);//wrong with b, ok with a // %o printf("unsigned octal like %o.\n", 100); // %x printf("unsigned hexadecimal integer like %x.\n", 100); // %f printf("decimal floating point, lowercase like %f.\n", 2.333f); // %F printf("decimal floating point, uppercase like %F.\n", 2.333f); // %e printf("scientific notation(mantissa/exponent), lowercase like %e.\n", 2e5); // %E printf("scientific notation(mantissa/exponent), uppercase like %E.\n", 2e5); // %g printf("use the shortest representation %%e or %%f like %g.\n", 234.334f); // %G printf("use the shortest representation %%E or %%F like %G.\n", 234.334f); // %a printf("hexadecimal floating point, lowercase like %a.\n", 1.2f); // %A printf("hexadecimal floating point, uppercase like %A.\n", 1.2f); // %c printf("character like %c.\n", a); printf("character like %c.\n", 'a'); // %s printf("string like %s.\n", "aaaa"); // %p char* buffer = (char*)malloc(sizeof(char) * 4); memset(&buffer, 0, sizeof(buffer)); buffer = "aaa"; printf("pointer address like %p.\n", buffer); // %n int* len = (int*)malloc(sizeof(int)); *len = 4; printf("nothing printed like %n.\n", len); // %% printf("double %% to one %%.\n");
sub-specifier
parameter
// n$ printf("to be output multiple times, using varying format specifiers or in different orders like %2$d, %1$d", 1, 2); printf("to be output multiple times, using varying format specifiers or in different orders like %1$#x, %1$#x", 16);
flags
// + printf("denote the sign of a number like %+d.\n", 2); printf("denote the sign of a number like %+d.\n", -2); // space printf("prefixed non-negative signed numbers with a space like % d.\n", 2); printf("prefixed non-negative signed numbers with a space like % d.\n", 2); // - printf("left align the output like %10d.\n", 123321); printf("left align the output like %10d.\n", 321); printf("left align the output like %-10d.\n", 123321); printf("left align the output like %-10d.\n", 321); // 0 printf("left align the output like %010d.\n", 321); // #// printf("hold the trailing zeros like %g.\n", 2.000f);// printf("hold the trailing zeros like %#g.\n", 2.000f);// printf("with a demical point like %f.\n", 2.f);// printf("with a demical point like %#f.\n", 2.f);
width
// (number) printf("Minimum number of characters to be printed like %3d.\n", 23423); printf("Minimum number of characters to be printed like %10d.\n", 23423); // * printf ("Width trick: %*d.\n", 5, 10);
precision
// .number printf("minimum number of digits to be written like %.3d.\n", 23423); printf("minimum number of digits to be written like %.10d.\n", 23423); printf("minimum number of digits to be written like %.10x.\n", 23423); printf("minimum number of digits to be written like %.5f.\n", 3.232323423); // .* printf("minimum number of digits to be written like %.*f.\n", 5, 3.232323423);
length
//length // l ll long d = 22; long long int e = 22; printf("long integer like %ld.\n", d); printf("long long integer like %lld.\n", e); // hh h char f = 'a'; short g = 22; printf("signed char like %hhd.\n", f); printf("short int like %hd.\n", g); // z size_t t = 22; printf("size_t like %zd.\n", t);
0 0
- printf 各种参数总结
- printf 参数。。。
- printf参数
- printf 参数
- printf总结
- printf中输出double的占位符、printf和scanf对于各种格式说明符可以接受的参数类型
- 各种视频的参数比较总结表
- printf和scanf对于各种格式说明符可以接受的参数类型
- Printf参数详解
- printf 参数详解
- printf函数可变参数
- 变参数printf解析
- Printf参数详解
- Printf参数详解
- printf函数参数问题
- 可变参数与printf
- Printf参数详解!
- printf参数介绍
- Ignatius and the Princess III
- Codeforces Beta Round #86 (Div. 1 Only) --- Grammar Lessons
- 抛硬币的两种思维方式
- IT痴汉的工作现状18-思维定式
- [LeetCode OJ]Single number II
- printf 各种参数总结
- thymeleaf模板引擎和shiro框架的整合
- hibernate学习笔记
- c++知识点之 函数指针
- ORA-00937
- HDU—— 2087 剪花布条
- Android数据库高手秘籍(六)——LitePal的修改和删除操作
- Leetcode-Swap Nodes in Pairs
- xcode armv6 armv7 armv7s arm64