转义字符

查询: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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容