printf 转义序列和转换字符%
2016-08-23 14:50
141 查看
The usually used output statement is printf (). It is one of the library functions.
Syntax : printf (“format string”, argument list);
Format string may be a collection of escape sequence or/and conversion specification or/and string constant. The format string directs the printf function to display the entire text enclosed within the double
quotes without any change.
Escape sequence:
Escape sequence is a pair of character. The first letter is a slash followed by a character. Escape sequence help us to represent within the format string invisible and non-printed character although there
are physically two characters in any escape sequence. It actually represents only one. The various escape sequences are
Conversion specification:
Conversion specification is also a pair of character. it is preceded by % and followed by a quote which may be a character. The Conversion specification inscribes the printf() function that it could print
some value at that location in the text. The Conversion characters supported by C are
The following program illustrates the use of puts function.
Syntax : printf (“format string”, argument list);
Format string may be a collection of escape sequence or/and conversion specification or/and string constant. The format string directs the printf function to display the entire text enclosed within the double
quotes without any change.
Escape sequence:
Escape sequence is a pair of character. The first letter is a slash followed by a character. Escape sequence help us to represent within the format string invisible and non-printed character although there
are physically two characters in any escape sequence. It actually represents only one. The various escape sequences are
Escape sequence | Meaning | ||||
\n | New line | ||||
\t | Tab | ||||
\b | Back space | ||||
\a | Bell | ||||
\o | Null character | ||||
\? | To print question mark | ||||
\\ | To print slash | ||||
\' | To print single quote | ||||
\" | To print double quote |
Conversion specification is also a pair of character. it is preceded by % and followed by a quote which may be a character. The Conversion specification inscribes the printf() function that it could print
some value at that location in the text. The Conversion characters supported by C are
Conversion character | Meaning | ||||
%d | Data item is displayed as a signed decimal integer. | ||||
%i | Data item is displayed as a single decimal integer. | ||||
%f | Data item is displayed as a floating-point value without an exponent. | ||||
%c | Data item is displayed as a single character. | ||||
%e | Data item is displayed as a floating-point value with an exponent. | ||||
%g | Data item is displayed as a floating-point value using either e-type or f-type conversion depending on value. | ||||
%o | Data item is displayed as an octal integer, without a leading zero. | ||||
%s | Data item is displayed as string. | ||||
%u | Data item is displayed as an unsigned decimal integer. | ||||
%x | Data item is displayed as a hexadecimal integer, without a leading 0x. |
转义字符: \0 :字符串结束标志; \n :换行(ascⅱ码为10); \t :横向跳格; \b :退格; \r :回车(ascⅱ码为13); \f :走纸换页; \\ :字符\(ascⅱ码为92); \' :单引号; '\"':双引号; \ddd:用8进制表示字符; \xhh:用16进制表示字符 如果输入空串的话,程序就会输出 thanks
相关文章推荐
- C语言转义序列,printf双引号内的特殊转义字符
- IIS7.0提示“请求筛选模块被配置为拒绝包含双重转义序列的请求”处理办法
- ES2018 新特征之:非转义序列的模板字符串
- c语言-转义序列
- php将十六进制转义序列转换成字符串
- C++中的转义序列
- 显示一数据表内容,提示“无法识别的转义序列”
- CS1009 无法识别的转义序列
- 转义序列和反转义(&#x)
- 请求筛选模块被配置为拒绝包含双重转义序列的请求
- IIS8.0, IIS7.0提示“请求筛选模块被配置为拒绝包含双重转义序列的请求”处理办法
- python 中的字符串转义序列、字符串格式化、操作符、关键字总结
- django 模板html自动转义符号和处理字符串在序列中自动加u
- C++中的转义序列
- IIS7.0提示“请求筛选模块被配置为拒绝包含双重转义序列的请求”处理办法
- 非打印字符-转义序列
- IIS8.0, IIS7.0提示“请求筛选模块被配置为拒绝包含双重转义序列的请求”处理办法
- IIS7.0、IIS7.5、IIS8.0等提示“请求筛选模块被配置为拒绝包含双重转义序列的请求”的解决方法小结
- 【javascript基础知识】javascript中的转义序列和特殊数值常量
- 转义序列