printf 转义序列和转换字符%

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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值