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
| 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:
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. |
The following program illustrates the use of puts function.
转义字符:
\0 :字符串结束标志;
\n :换行(ascⅱ码为10);
\t :横向跳格;
\b :退格;
\r :回车(ascⅱ码为13);
\f :走纸换页;
\\ :字符\(ascⅱ码为92);
\' :单引号;
'\"':双引号;
\ddd:用8进制表示字符;
\xhh:用16进制表示字符
如果输入空串的话,程序就会输出 thanks
本文详细介绍了C语言中常用的输出函数printf()的使用方法,包括格式字符串、转义序列、转换说明等核心概念,并提供了示例程序。
476

被折叠的 条评论
为什么被折叠?



