查询:man 1 printf
\" double quote
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\e escape
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\NNN byte with octal value NNN (1 to 3 digits)
\xHH byte with hexadecimal value HH (1 to 2 digits)
\uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)
\UHHHHHHHH
Unicode character with hex value HHHHHHHH (8 digits)
%% a single %
%b ARGUMENT as a string with '\' escapes interpreted, except that octal
escapes are of the form \0 or \0NNN
%q ARGUMENT is printed in a format that can be reused as shell input,
escaping non-printable characters with the proposed POSIX $'' syntax.
#include<stdio.h>
void print_square(void)
{
printf("\
* * * * *\n\
* *\n\
* *\n\
* *\n\
* * * * *\n");
}
int main()
{
print_square();
printf("\\a:\a\n");
printf("\\b:\btest\n");
printf("test\n");
printf("\\f:\f\n");
printf("\\r:\r\n");
printf("\\t:\ttest\n");
printf("\\v:test\vtest\n");
printf("\\?:\?\n");
printf("\\0:\0test\n");
printf("\\ddd:\377\n"); //最大值255
printf("\\xhh:\xff\n"); //最大值255
return 0;
}
//输出
* * * * *
* *
* *
* *
* * * * *
\a:
\btest
test
\f:
\r:
\t: test
\v:test
test
\?:?
\0:\ddd:�
\xhh:�
字符串"abcd\0ef"存储方式为:abcd\0ef\0
#include<stdio.h>
int main()
{
int i=0;
char test[]="abcd\0ef";
while(i < sizeof(test))
{
printf("%c\n",test[i]);
i++;
}
printf("%ld\n", sizeof(test));
printf("test:%s\n", test);
return 0;
}
//输出
a
b
c
d
e
f
8
test:abcd